aioampio 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aioampio/__init__.py +5 -0
- aioampio/bridge.py +186 -0
- aioampio/cli.py +37 -0
- aioampio/codec/__init__.py +1 -0
- aioampio/codec/ampio.py +485 -0
- aioampio/codec/base.py +27 -0
- aioampio/codec/helper.py +31 -0
- aioampio/codec/registry.py +53 -0
- aioampio/config.py +124 -0
- aioampio/controllers/__init__.py +1 -0
- aioampio/controllers/alarm_control_panels.py +56 -0
- aioampio/controllers/areas.py +15 -0
- aioampio/controllers/base.py +211 -0
- aioampio/controllers/binary_sensor.py +12 -0
- aioampio/controllers/climates.py +31 -0
- aioampio/controllers/covers.py +77 -0
- aioampio/controllers/devices.py +13 -0
- aioampio/controllers/events.py +27 -0
- aioampio/controllers/floors.py +15 -0
- aioampio/controllers/lights.py +110 -0
- aioampio/controllers/sensor.py +12 -0
- aioampio/controllers/switch.py +43 -0
- aioampio/controllers/text.py +12 -0
- aioampio/controllers/utils.py +48 -0
- aioampio/controllers/valves.py +56 -0
- aioampio/entity_manager.py +93 -0
- aioampio/models/__init__.py +1 -0
- aioampio/models/alarm_control_panel.py +49 -0
- aioampio/models/area.py +17 -0
- aioampio/models/binary_sensor.py +26 -0
- aioampio/models/climate.py +35 -0
- aioampio/models/config.py +309 -0
- aioampio/models/cover.py +71 -0
- aioampio/models/device.py +22 -0
- aioampio/models/feature.py +48 -0
- aioampio/models/floor.py +19 -0
- aioampio/models/light.py +51 -0
- aioampio/models/resource.py +21 -0
- aioampio/models/sensor.py +51 -0
- aioampio/models/switch.py +26 -0
- aioampio/models/text.py +24 -0
- aioampio/models/valve.py +67 -0
- aioampio/outputs/__init__.py +6 -0
- aioampio/outputs/stdout.py +46 -0
- aioampio/transport.py +80 -0
- aioampio/util.py +9 -0
- aioampio-0.1.2.dist-info/METADATA +39 -0
- aioampio-0.1.2.dist-info/RECORD +52 -0
- aioampio-0.1.2.dist-info/WHEEL +5 -0
- aioampio-0.1.2.dist-info/entry_points.txt +2 -0
- aioampio-0.1.2.dist-info/licenses/LICENSE +201 -0
- aioampio-0.1.2.dist-info/top_level.txt +1 -0
aioampio/__init__.py
ADDED
aioampio/bridge.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Ampio Bridge."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from caneth import CANFrame
|
|
7
|
+
|
|
8
|
+
from aioampio.config import AmpioConfig
|
|
9
|
+
from aioampio.controllers.alarm_control_panels import AlarmControlPanelsController
|
|
10
|
+
from aioampio.controllers.areas import AreasController
|
|
11
|
+
from aioampio.controllers.binary_sensor import BinarySensorsController
|
|
12
|
+
from aioampio.controllers.climates import ClimatesController
|
|
13
|
+
from aioampio.controllers.covers import CoversController
|
|
14
|
+
from aioampio.controllers.sensor import SensorsController
|
|
15
|
+
from aioampio.controllers.switch import SwitchesController
|
|
16
|
+
from aioampio.controllers.text import TextsController
|
|
17
|
+
from aioampio.controllers.floors import FloorsController
|
|
18
|
+
from aioampio.controllers.valves import ValvesController
|
|
19
|
+
from aioampio.outputs.stdout import StdoutOutput
|
|
20
|
+
|
|
21
|
+
from .controllers.lights import LightsController
|
|
22
|
+
from .controllers.devices import DevicesController
|
|
23
|
+
|
|
24
|
+
from .codec.registry import registry
|
|
25
|
+
from .entity_manager import EntityManager
|
|
26
|
+
from .transport import CanethTransport
|
|
27
|
+
from .models.resource import ResourceTypes
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AmpioBridge: # pylint: disable=too-many-instance-attributes
|
|
31
|
+
"""Ampio Bridge main class."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, cfg_path: str, host: str, port: int) -> None:
|
|
34
|
+
"""Initialize the Ampio Bridge."""
|
|
35
|
+
self._host = host
|
|
36
|
+
self._port = port
|
|
37
|
+
self._cfg_path = cfg_path
|
|
38
|
+
|
|
39
|
+
self.logger = logging.getLogger(f"{__package__}[{self._host}]")
|
|
40
|
+
|
|
41
|
+
self.config = AmpioConfig(self)
|
|
42
|
+
|
|
43
|
+
self.transport = CanethTransport(self._host, self._port)
|
|
44
|
+
self.entities = EntityManager(self)
|
|
45
|
+
|
|
46
|
+
self._devices = DevicesController(self)
|
|
47
|
+
self._lights = LightsController(self)
|
|
48
|
+
self._alarm_control_panels = AlarmControlPanelsController(self)
|
|
49
|
+
self._texts = TextsController(self)
|
|
50
|
+
self._binary_sensors = BinarySensorsController(self)
|
|
51
|
+
self._sensor = SensorsController(self)
|
|
52
|
+
self._floors = FloorsController(self)
|
|
53
|
+
self._areas = AreasController(self)
|
|
54
|
+
self._switches = SwitchesController(self)
|
|
55
|
+
self._covers = CoversController(self)
|
|
56
|
+
self._valves = ValvesController(self)
|
|
57
|
+
self._climates = ClimatesController(self)
|
|
58
|
+
|
|
59
|
+
self._outputs: list[StdoutOutput] = []
|
|
60
|
+
self._whitelist: set[int] = set()
|
|
61
|
+
|
|
62
|
+
def set_filters(self) -> None:
|
|
63
|
+
"""Set CAN filters based on device whitelist from configuration."""
|
|
64
|
+
self._whitelist: set[int] = {
|
|
65
|
+
item.can_id # type: ignore # noqa: PGH003
|
|
66
|
+
for item in self.config
|
|
67
|
+
if item.type == ResourceTypes.DEVICE and hasattr(item, "can_id")
|
|
68
|
+
}
|
|
69
|
+
if self._whitelist:
|
|
70
|
+
# filters = [(can_id, 0xFE, None) for can_id in self._whitelist]
|
|
71
|
+
filters = [(can_id, None, None) for can_id in self._whitelist]
|
|
72
|
+
self.transport.set_filters(filters)
|
|
73
|
+
self.logger.info(
|
|
74
|
+
"Device whitelist applied for %i devices", len(self._whitelist)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def initialize_outputs(self) -> None:
|
|
78
|
+
"""Initialize output handlers based on configuration."""
|
|
79
|
+
for out in self.config.outputs:
|
|
80
|
+
if out.type == "stdout":
|
|
81
|
+
self._outputs.append(StdoutOutput(fmt=out.format))
|
|
82
|
+
|
|
83
|
+
async def initialize(self) -> None:
|
|
84
|
+
"""Initialize the bridge."""
|
|
85
|
+
await self.config.initialize(self._cfg_path)
|
|
86
|
+
self.set_filters()
|
|
87
|
+
self.initialize_outputs()
|
|
88
|
+
|
|
89
|
+
await asyncio.gather(
|
|
90
|
+
self._floors.initialize(),
|
|
91
|
+
self._areas.initialize(),
|
|
92
|
+
self._devices.initialize(),
|
|
93
|
+
self._lights.initialize(),
|
|
94
|
+
self._alarm_control_panels.initialize(),
|
|
95
|
+
self._texts.initialize(),
|
|
96
|
+
self._binary_sensors.initialize(),
|
|
97
|
+
self._sensor.initialize(),
|
|
98
|
+
self._switches.initialize(),
|
|
99
|
+
self._covers.initialize(),
|
|
100
|
+
self._valves.initialize(),
|
|
101
|
+
self._climates.initialize(),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
async def start(self) -> None:
|
|
105
|
+
"""Start the bridge."""
|
|
106
|
+
self.transport.on_frame(self._on_frame)
|
|
107
|
+
await self.transport.start()
|
|
108
|
+
|
|
109
|
+
async def stop(self) -> None:
|
|
110
|
+
"""Stop the bridge."""
|
|
111
|
+
await self.transport.close()
|
|
112
|
+
|
|
113
|
+
async def _on_frame(self, frame: CANFrame) -> None:
|
|
114
|
+
"""Handle incoming CAN frame."""
|
|
115
|
+
msgs = registry().decode(frame)
|
|
116
|
+
if msgs:
|
|
117
|
+
# store/update entity state
|
|
118
|
+
for msg in msgs:
|
|
119
|
+
await self.entities.apply_message(msg)
|
|
120
|
+
# emit outputs for visibility
|
|
121
|
+
for out in self._outputs:
|
|
122
|
+
for msg in msgs:
|
|
123
|
+
out.emit_msg(msg)
|
|
124
|
+
else:
|
|
125
|
+
for out in self._outputs:
|
|
126
|
+
out.emit_raw(frame)
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def floors(self) -> FloorsController:
|
|
130
|
+
"""Return the floors controller."""
|
|
131
|
+
return self._floors
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def areas(self) -> AreasController:
|
|
135
|
+
"""Return the areas controller."""
|
|
136
|
+
return self._areas
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def devices(self) -> DevicesController:
|
|
140
|
+
"""Return the devices managed by the bridge."""
|
|
141
|
+
return self._devices
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def lights(self) -> LightsController:
|
|
145
|
+
"""Return the lights controller."""
|
|
146
|
+
return self._lights
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def alarm_control_panels(self) -> AlarmControlPanelsController:
|
|
150
|
+
"""Return the alarm control panels controller."""
|
|
151
|
+
return self._alarm_control_panels
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def texts(self) -> TextsController:
|
|
155
|
+
"""Return the texts controller."""
|
|
156
|
+
return self._texts
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def binary_sensors(self) -> BinarySensorsController:
|
|
160
|
+
"""Return the binary sensors controller."""
|
|
161
|
+
return self._binary_sensors
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def sensors(self) -> SensorsController:
|
|
165
|
+
"""Return the sensors controller."""
|
|
166
|
+
return self._sensor
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def switches(self) -> SwitchesController:
|
|
170
|
+
"""Return the switches controller."""
|
|
171
|
+
return self._switches
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
def covers(self) -> CoversController:
|
|
175
|
+
"""Return the covers controller."""
|
|
176
|
+
return self._covers
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def valves(self) -> ValvesController:
|
|
180
|
+
"""Return the valves controller."""
|
|
181
|
+
return self._valves
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def climates(self) -> ClimatesController:
|
|
185
|
+
"""Return the climates controller."""
|
|
186
|
+
return self._climates
|
aioampio/cli.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Example CLI command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
from .bridge import AmpioBridge
|
|
10
|
+
|
|
11
|
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s: %(message)s")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main(argv: list[str] | None = None) -> None:
|
|
15
|
+
"""Start for the CLI."""
|
|
16
|
+
ap = argparse.ArgumentParser(
|
|
17
|
+
prog="aioampio", description="Ampio Bridge Test Harness"
|
|
18
|
+
)
|
|
19
|
+
ap.add_argument("--config", required=True, help="Path to YAML configuration file")
|
|
20
|
+
ap.add_argument("--host", required=True, help="Host to connect to")
|
|
21
|
+
ap.add_argument("--port", type=int, default=20001, help="Port to connect to")
|
|
22
|
+
args = ap.parse_args(argv)
|
|
23
|
+
|
|
24
|
+
bridge = AmpioBridge(args.config, args.host, args.port)
|
|
25
|
+
|
|
26
|
+
async def runner() -> None:
|
|
27
|
+
await bridge.initialize()
|
|
28
|
+
await bridge.start()
|
|
29
|
+
stop_event = asyncio.Event()
|
|
30
|
+
try:
|
|
31
|
+
await stop_event.wait()
|
|
32
|
+
except KeyboardInterrupt:
|
|
33
|
+
pass
|
|
34
|
+
finally:
|
|
35
|
+
await bridge.stop()
|
|
36
|
+
|
|
37
|
+
asyncio.run(runner())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Ampio Codec Registry."""
|