1 """The Z-Wave-Me WS integration."""
3 from zwave_me_ws
import ZWaveMe, ZWaveMeData
12 from .const
import DOMAIN, PLATFORMS, ZWaveMePlatform
14 ZWAVE_ME_PLATFORMS = [platform.value
for platform
in ZWaveMePlatform]
18 """Set up Z-Wave-Me from a config entry."""
19 hass.data.setdefault(DOMAIN, {})
21 if await controller.async_establish_connection():
23 registry = dr.async_get(hass)
24 controller.remove_stale_devices(registry)
26 raise ConfigEntryNotReady
30 """Unload a config entry."""
32 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
34 controller = hass.data[DOMAIN].pop(entry.entry_id)
35 await controller.zwave_api.close_ws()
40 """Main ZWave-Me API class."""
42 def __init__(self, hass: HomeAssistant, config: ConfigEntry) ->
None:
43 """Create the API instance."""
44 self.device_ids: set = set()
53 token=self.
configconfig.data[CONF_TOKEN],
54 url=self.
configconfig.data[CONF_URL],
55 platforms=ZWAVE_ME_PLATFORMS,
60 """Get connection status."""
64 """Send signal to create device."""
65 if device.id
in self.device_ids:
69 self.
_hass_hass, f
"ZWAVE_ME_NEW_{device.deviceType.upper()}", device
71 self.device_ids.
add(device.id)
74 """Create multiple devices."""
75 for device
in devices:
76 if device.deviceType
in ZWAVE_ME_PLATFORMS
and self.
platforms_initedplatforms_inited:
80 """Send signal to update device."""
84 """Send signal to set device unavailable."""
88 """Send signal to destroy device."""
92 """Remove old-format devices in the registry."""
93 for device_id
in self.device_ids:
94 device = registry.async_get_device(
95 identifiers={(DOMAIN, f
"{self.config.unique_id}-{device_id}")}
97 if device
is not None:
98 registry.async_remove_device(device.id)
102 hass: HomeAssistant, entry: ConfigEntry, controller: ZWaveMeController
104 """Set up platforms."""
105 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
106 controller.platforms_inited =
True
108 await hass.async_add_executor_job(controller.zwave_api.get_devices)
None __init__(self, HomeAssistant hass, ConfigEntry config)
None on_device_update(self, ZWaveMeData new_info)
None on_device_create(self, list[ZWaveMeData] devices)
None on_device_unavailable(self, str device_id)
def remove_stale_devices(self, dr.DeviceRegistry registry)
def async_establish_connection(self)
None add_device(self, ZWaveMeData device)
None on_device_destroy(self, str device_id)
bool add(self, _T matcher)
CachedConnection get_connection(HomeAssistant hass, str address)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
None async_setup_platforms(HomeAssistant hass, ConfigEntry entry, ZWaveMeController controller)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)