Skip to content

Commit 735b2f1

Browse files
committed
Add support for MQTT
This is currently untested.
1 parent bc8a5a3 commit 735b2f1

17 files changed

+2794
-595
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ What it can do:
2626
- **Even more**
2727
There are some more goodies in to docs below. Enjoy!
2828

29-
_Note: currently this is limited to Blue switches using ZHA, but ideally Z2M and other Inovelli switches will be added in the future._
29+
_Note: currently this is limited to Blue switches using ZHA or Zigbee2MQTT, but other Inovelli switches will be added in the future._
3030

3131
**Configure notifications** for multiple switches easily:
3232

@@ -272,6 +272,12 @@ Restore state functionality is provided via a subset of entities:
272272

273273
If you disable these entities, it is possible that various other entities may not be restored after restarting Home Assistant.
274274

275+
##### Zigbee2MQTT
276+
277+
While supported by the Blue switch firmware, Zigbee2MQTT does not yet provide events with an `action` for when a notification expires (it only supports, for instance, [`config_double`](https://www.zigbee2mqtt.io/devices/VZM35-SN.html#action-enum)).
278+
279+
This integration therefore handles notification expiration itself for switches configured with Zigbee2MQTT. This may change unexpectedly in the future—if and when it is possible, Lampie will change to sending durations to the firmware.
280+
275281
## More Screenshots
276282

277283
Once configured, the integration links the various entities to logical devices:

custom_components/lampie/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: LampieConfigEntry) -> bo
4545
_LOGGER.debug("setup %s with config:%s", entry.title, entry.data)
4646

4747
if DOMAIN not in hass.data:
48-
hass.data[DOMAIN] = LampieOrchestrator(hass)
48+
orchestrator = LampieOrchestrator(hass)
49+
hass.data[DOMAIN] = orchestrator
50+
51+
await orchestrator.setup()
4952

5053
coordinator = LampieUpdateCoordinator(hass, entry)
51-
orchestrator: LampieOrchestrator = hass.data[DOMAIN]
52-
orchestrator.add_coordinator(coordinator)
54+
orchestrator = hass.data[DOMAIN]
55+
await orchestrator.add_coordinator(coordinator)
5356
entry.runtime_data = LampieConfigEntryRuntimeData(
5457
orchestrator=orchestrator,
5558
coordinator=coordinator,
@@ -79,7 +82,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: LampieConfigEntry) -> b
7982
unload_ok: bool = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
8083

8184
if orchestrator := entry.runtime_data.orchestrator:
82-
orchestrator.remove_coordinator(coordinator)
85+
await orchestrator.remove_coordinator(coordinator)
8386

8487
if orchestrator.teardown() and orchestrator == hass.data.get(DOMAIN):
8588
hass.data.pop(DOMAIN)

custom_components/lampie/config_flow.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,20 @@ def _is_inovelli_switch(
651651
entity_registry: er.EntityRegistry,
652652
entity_id: str,
653653
) -> bool:
654-
"""Check if entity_id should be included for dependent entities.
654+
"""Check if entity_id should be included for the list of switches.
655655
656-
Determine if an entity_id represents an entity with a `state_class` of
657-
`total_increasing` and a `unit_of_measurement` of `km`.
656+
Determine if an entity_id represents an Inovelli switch.
658657
659658
Returns:
660659
A flag indicating if the entity should be included.
661660
"""
662-
return bool(
663-
(entity := entity_registry.async_get(entity_id))
664-
and (device := device_registry.async_get(entity.device_id))
665-
and (model := device.model)
666-
and (model in INOVELLI_MODELS)
667-
)
661+
if (entity := entity_registry.async_get(entity_id)) and (
662+
device := device_registry.async_get(entity.device_id)
663+
):
664+
model = device.model
665+
model_id = device.model_id
666+
return model in INOVELLI_MODELS or model_id in INOVELLI_MODELS
667+
return False
668668

669669

670670
def _is_listlike[T](value: T) -> bool:

custom_components/lampie/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"@wbyoung"
66
],
77
"config_flow": true,
8-
"dependencies": [],
8+
"dependencies": ["mqtt"],
99
"documentation": "https://github.com/wbyoung/lampie",
1010
"homekit": {},
1111
"iot_class": "calculated",

0 commit comments

Comments
 (0)