lifx-emulator 2.4.0__py3-none-any.whl → 3.0.1__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.
Files changed (68) hide show
  1. lifx_emulator-3.0.1.dist-info/METADATA +102 -0
  2. lifx_emulator-3.0.1.dist-info/RECORD +18 -0
  3. lifx_emulator-3.0.1.dist-info/entry_points.txt +2 -0
  4. lifx_emulator_app/__init__.py +10 -0
  5. {lifx_emulator → lifx_emulator_app}/__main__.py +2 -3
  6. {lifx_emulator → lifx_emulator_app}/api/__init__.py +1 -1
  7. {lifx_emulator → lifx_emulator_app}/api/app.py +3 -3
  8. {lifx_emulator → lifx_emulator_app}/api/mappers/__init__.py +1 -1
  9. {lifx_emulator → lifx_emulator_app}/api/mappers/device_mapper.py +1 -1
  10. {lifx_emulator → lifx_emulator_app}/api/models.py +1 -2
  11. lifx_emulator_app/api/routers/__init__.py +11 -0
  12. {lifx_emulator → lifx_emulator_app}/api/routers/devices.py +2 -2
  13. {lifx_emulator → lifx_emulator_app}/api/routers/monitoring.py +1 -1
  14. {lifx_emulator → lifx_emulator_app}/api/routers/scenarios.py +1 -1
  15. lifx_emulator_app/api/services/__init__.py +8 -0
  16. {lifx_emulator → lifx_emulator_app}/api/services/device_service.py +3 -2
  17. lifx_emulator/__init__.py +0 -31
  18. lifx_emulator/api/routers/__init__.py +0 -11
  19. lifx_emulator/api/services/__init__.py +0 -8
  20. lifx_emulator/constants.py +0 -33
  21. lifx_emulator/devices/__init__.py +0 -37
  22. lifx_emulator/devices/device.py +0 -395
  23. lifx_emulator/devices/manager.py +0 -256
  24. lifx_emulator/devices/observers.py +0 -139
  25. lifx_emulator/devices/persistence.py +0 -308
  26. lifx_emulator/devices/state_restorer.py +0 -259
  27. lifx_emulator/devices/state_serializer.py +0 -157
  28. lifx_emulator/devices/states.py +0 -381
  29. lifx_emulator/factories/__init__.py +0 -39
  30. lifx_emulator/factories/builder.py +0 -375
  31. lifx_emulator/factories/default_config.py +0 -158
  32. lifx_emulator/factories/factory.py +0 -252
  33. lifx_emulator/factories/firmware_config.py +0 -77
  34. lifx_emulator/factories/serial_generator.py +0 -82
  35. lifx_emulator/handlers/__init__.py +0 -39
  36. lifx_emulator/handlers/base.py +0 -49
  37. lifx_emulator/handlers/device_handlers.py +0 -322
  38. lifx_emulator/handlers/light_handlers.py +0 -503
  39. lifx_emulator/handlers/multizone_handlers.py +0 -249
  40. lifx_emulator/handlers/registry.py +0 -110
  41. lifx_emulator/handlers/tile_handlers.py +0 -488
  42. lifx_emulator/products/__init__.py +0 -28
  43. lifx_emulator/products/generator.py +0 -1079
  44. lifx_emulator/products/registry.py +0 -1530
  45. lifx_emulator/products/specs.py +0 -284
  46. lifx_emulator/products/specs.yml +0 -386
  47. lifx_emulator/protocol/__init__.py +0 -1
  48. lifx_emulator/protocol/base.py +0 -446
  49. lifx_emulator/protocol/const.py +0 -8
  50. lifx_emulator/protocol/generator.py +0 -1384
  51. lifx_emulator/protocol/header.py +0 -159
  52. lifx_emulator/protocol/packets.py +0 -1351
  53. lifx_emulator/protocol/protocol_types.py +0 -817
  54. lifx_emulator/protocol/serializer.py +0 -379
  55. lifx_emulator/repositories/__init__.py +0 -22
  56. lifx_emulator/repositories/device_repository.py +0 -155
  57. lifx_emulator/repositories/storage_backend.py +0 -107
  58. lifx_emulator/scenarios/__init__.py +0 -22
  59. lifx_emulator/scenarios/manager.py +0 -322
  60. lifx_emulator/scenarios/models.py +0 -112
  61. lifx_emulator/scenarios/persistence.py +0 -241
  62. lifx_emulator/server.py +0 -464
  63. lifx_emulator-2.4.0.dist-info/METADATA +0 -107
  64. lifx_emulator-2.4.0.dist-info/RECORD +0 -62
  65. lifx_emulator-2.4.0.dist-info/entry_points.txt +0 -2
  66. lifx_emulator-2.4.0.dist-info/licenses/LICENSE +0 -35
  67. {lifx_emulator-2.4.0.dist-info → lifx_emulator-3.0.1.dist-info}/WHEEL +0 -0
  68. {lifx_emulator → lifx_emulator_app}/api/templates/dashboard.html +0 -0
@@ -1,322 +0,0 @@
1
- """Device packet handlers."""
2
-
3
- from __future__ import annotations
4
-
5
- import logging
6
- import time
7
- from typing import TYPE_CHECKING, Any
8
-
9
- from lifx_emulator.handlers.base import PacketHandler
10
- from lifx_emulator.protocol.packets import Device
11
- from lifx_emulator.protocol.protocol_types import DeviceService as ProtocolDeviceService
12
-
13
- if TYPE_CHECKING:
14
- from lifx_emulator.devices import DeviceState
15
-
16
- logger = logging.getLogger(__name__)
17
-
18
-
19
- class GetServiceHandler(PacketHandler):
20
- """Handle DeviceGetService (2) -> DeviceStateService (3)."""
21
-
22
- PKT_TYPE = Device.GetService.PKT_TYPE
23
-
24
- def handle(
25
- self, device_state: DeviceState, packet: Any | None, res_required: bool
26
- ) -> list[Any]:
27
- logger.debug(
28
- "Sending StateService: %s [%s]",
29
- ProtocolDeviceService.UDP,
30
- device_state.port,
31
- )
32
- return [
33
- Device.StateService(
34
- service=ProtocolDeviceService.UDP, port=device_state.port
35
- )
36
- ]
37
-
38
-
39
- class GetPowerHandler(PacketHandler):
40
- """Handle DeviceGetPower (20) -> DeviceStatePower (22)."""
41
-
42
- PKT_TYPE = Device.GetPower.PKT_TYPE
43
-
44
- def handle(
45
- self, device_state: DeviceState, packet: Any | None, res_required: bool
46
- ) -> list[Any]:
47
- return [Device.StatePower(level=device_state.power_level)]
48
-
49
-
50
- class SetPowerHandler(PacketHandler):
51
- """Handle DeviceSetPower (21) -> DeviceStatePower (22)."""
52
-
53
- PKT_TYPE = Device.SetPower.PKT_TYPE
54
-
55
- def handle(
56
- self,
57
- device_state: DeviceState,
58
- packet: Device.SetPower | None,
59
- res_required: bool,
60
- ) -> list[Any]:
61
- if packet:
62
- device_state.power_level = packet.level
63
- logger.info("Power set to %s", device_state.power_level)
64
-
65
- if res_required:
66
- return [Device.StatePower(level=device_state.power_level)]
67
- return []
68
-
69
-
70
- class GetLabelHandler(PacketHandler):
71
- """Handle DeviceGetLabel (23) -> DeviceStateLabel (25)."""
72
-
73
- PKT_TYPE = Device.GetLabel.PKT_TYPE
74
-
75
- def handle(
76
- self, device_state: DeviceState, packet: Any | None, res_required: bool
77
- ) -> list[Any]:
78
- return [Device.StateLabel(label=device_state.label)]
79
-
80
-
81
- class SetLabelHandler(PacketHandler):
82
- """Handle DeviceSetLabel (24) -> DeviceStateLabel (25)."""
83
-
84
- PKT_TYPE = Device.SetLabel.PKT_TYPE
85
-
86
- def handle(
87
- self,
88
- device_state: DeviceState,
89
- packet: Device.SetLabel | None,
90
- res_required: bool,
91
- ) -> list[Any]:
92
- if packet:
93
- device_state.label = packet.label
94
- logger.info("Label set to '%s'", device_state.label)
95
-
96
- if res_required:
97
- return [Device.StateLabel(label=device_state.label)]
98
- return []
99
-
100
-
101
- class GetVersionHandler(PacketHandler):
102
- """Handle DeviceGetVersion (32) -> DeviceStateVersion (33)."""
103
-
104
- PKT_TYPE = Device.GetVersion.PKT_TYPE
105
-
106
- def handle(
107
- self, device_state: DeviceState, packet: Any | None, res_required: bool
108
- ) -> list[Any]:
109
- return [
110
- Device.StateVersion(
111
- vendor=device_state.vendor, product=device_state.product
112
- )
113
- ]
114
-
115
-
116
- class GetInfoHandler(PacketHandler):
117
- """Handle DeviceGetInfo (34) -> DeviceStateInfo (35)."""
118
-
119
- PKT_TYPE = Device.GetInfo.PKT_TYPE
120
-
121
- def handle(
122
- self, device_state: DeviceState, packet: Any | None, res_required: bool
123
- ) -> list[Any]:
124
- current_time = int(time.time() * 1e9) # nanoseconds
125
- return [
126
- Device.StateInfo(
127
- time=current_time, uptime=device_state.uptime_ns, downtime=0
128
- )
129
- ]
130
-
131
-
132
- class GetHostFirmwareHandler(PacketHandler):
133
- """Handle DeviceGetHostFirmware (14) -> DeviceStateHostFirmware (15)."""
134
-
135
- PKT_TYPE = Device.GetHostFirmware.PKT_TYPE
136
-
137
- def handle(
138
- self, device_state: DeviceState, packet: Any | None, res_required: bool
139
- ) -> list[Any]:
140
- return [
141
- Device.StateHostFirmware(
142
- build=device_state.build_timestamp,
143
- version_minor=device_state.version_minor,
144
- version_major=device_state.version_major,
145
- )
146
- ]
147
-
148
-
149
- class GetWifiInfoHandler(PacketHandler):
150
- """Handle DeviceGetWifiInfo (16) -> DeviceStateWifiInfo (17)."""
151
-
152
- PKT_TYPE = Device.GetWifiInfo.PKT_TYPE
153
-
154
- def handle(
155
- self, device_state: DeviceState, packet: Any | None, res_required: bool
156
- ) -> list[Any]:
157
- return [Device.StateWifiInfo(signal=device_state.wifi_signal)]
158
-
159
-
160
- class GetLocationHandler(PacketHandler):
161
- """Handle DeviceGetLocation (48) -> DeviceStateLocation (50)."""
162
-
163
- PKT_TYPE = Device.GetLocation.PKT_TYPE
164
-
165
- def handle(
166
- self, device_state: DeviceState, packet: Any | None, res_required: bool
167
- ) -> list[Any]:
168
- return [
169
- Device.StateLocation(
170
- location=device_state.location_id,
171
- label=device_state.location_label,
172
- updated_at=device_state.location_updated_at,
173
- )
174
- ]
175
-
176
-
177
- class SetLocationHandler(PacketHandler):
178
- """Handle DeviceSetLocation (49) -> DeviceStateLocation (50)."""
179
-
180
- PKT_TYPE = Device.SetLocation.PKT_TYPE
181
-
182
- def handle(
183
- self,
184
- device_state: DeviceState,
185
- packet: Device.SetLocation | None,
186
- res_required: bool,
187
- ) -> list[Any]:
188
- if packet:
189
- device_state.location_id = packet.location
190
- device_state.location_label = packet.label
191
- device_state.location_updated_at = packet.updated_at
192
- loc_id = packet.location.hex()[:8]
193
- logger.info(
194
- "Location set to '%s' (id=%s...)", device_state.location_label, loc_id
195
- )
196
-
197
- if res_required:
198
- return [
199
- Device.StateLocation(
200
- location=device_state.location_id,
201
- label=device_state.location_label,
202
- updated_at=device_state.location_updated_at,
203
- )
204
- ]
205
- return []
206
-
207
-
208
- class GetGroupHandler(PacketHandler):
209
- """Handle DeviceGetGroup (51) -> DeviceStateGroup (53)."""
210
-
211
- PKT_TYPE = Device.GetGroup.PKT_TYPE
212
-
213
- def handle(
214
- self, device_state: DeviceState, packet: Any | None, res_required: bool
215
- ) -> list[Any]:
216
- return [
217
- Device.StateGroup(
218
- group=device_state.group_id,
219
- label=device_state.group_label,
220
- updated_at=device_state.group_updated_at,
221
- )
222
- ]
223
-
224
-
225
- class SetGroupHandler(PacketHandler):
226
- """Handle DeviceSetGroup (52) -> DeviceStateGroup (53)."""
227
-
228
- PKT_TYPE = Device.SetGroup.PKT_TYPE
229
-
230
- def handle(
231
- self,
232
- device_state: DeviceState,
233
- packet: Device.SetGroup | None,
234
- res_required: bool,
235
- ) -> list[Any]:
236
- if packet:
237
- device_state.group_id = packet.group
238
- device_state.group_label = packet.label
239
- device_state.group_updated_at = packet.updated_at
240
- grp_id = packet.group.hex()[:8]
241
- logger.info(
242
- "Group set to '%s' (id=%s...)", device_state.group_label, grp_id
243
- )
244
-
245
- if res_required:
246
- return [
247
- Device.StateGroup(
248
- group=device_state.group_id,
249
- label=device_state.group_label,
250
- updated_at=device_state.group_updated_at,
251
- )
252
- ]
253
- return []
254
-
255
-
256
- class EchoRequestHandler(PacketHandler):
257
- """Handle DeviceEchoRequest (58) -> DeviceEchoResponse (59)."""
258
-
259
- PKT_TYPE = Device.EchoRequest.PKT_TYPE
260
-
261
- def handle(
262
- self,
263
- device_state: DeviceState,
264
- packet: Device.EchoRequest | None,
265
- res_required: bool,
266
- ) -> list[Any]:
267
- payload = packet.payload if packet else b"\x00" * 64
268
- return [Device.EchoResponse(payload=payload[:64].ljust(64, b"\x00"))]
269
-
270
-
271
- class GetWifiFirmwareHandler(PacketHandler):
272
- """Handle DeviceGetWifiFirmware (18) -> DeviceStateWifiFirmware (19)."""
273
-
274
- PKT_TYPE = Device.GetWifiFirmware.PKT_TYPE
275
-
276
- def handle(
277
- self, device_state: DeviceState, packet: Any | None, res_required: bool
278
- ) -> list[Any]:
279
- build = int(time.time()) - 1000000000 # Example build timestamp
280
- return [
281
- Device.StateWifiFirmware(
282
- build=build,
283
- version_minor=device_state.version_minor,
284
- version_major=device_state.version_major,
285
- )
286
- ]
287
-
288
-
289
- class SetRebootHandler(PacketHandler):
290
- """Handle DeviceSetReboot (38) - just acknowledge, don't actually reboot."""
291
-
292
- PKT_TYPE = Device.SetReboot.PKT_TYPE
293
-
294
- def handle(
295
- self, device_state: DeviceState, packet: Any | None, res_required: bool
296
- ) -> list[Any]:
297
- serial = device_state.serial
298
- logger.info("Device %s: Received reboot request (ignored in emulator)", serial)
299
- # In a real device, this would trigger a reboot
300
- # In emulator, we just acknowledge it
301
- return []
302
-
303
-
304
- # List of all device handlers for easy registration
305
- ALL_DEVICE_HANDLERS = [
306
- GetServiceHandler(),
307
- GetPowerHandler(),
308
- SetPowerHandler(),
309
- GetLabelHandler(),
310
- SetLabelHandler(),
311
- GetVersionHandler(),
312
- GetInfoHandler(),
313
- GetHostFirmwareHandler(),
314
- GetWifiInfoHandler(),
315
- GetLocationHandler(),
316
- SetLocationHandler(),
317
- GetGroupHandler(),
318
- SetGroupHandler(),
319
- EchoRequestHandler(),
320
- GetWifiFirmwareHandler(),
321
- SetRebootHandler(),
322
- ]