Add config flow to insteon component (#36467)

* Squashed

* Fix requirements_all

* Update homeassistant/components/insteon/__init__.py

Only update options if the result is to create the entry.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/insteon/__init__.py

No return value needed.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Ref RESULT_TYPE_CREATE_ENTRY correctly

* Return result back to import config process

* Make DOMAIN ref more clear

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Tom Harris 2020-08-11 19:04:44 -04:00 committed by GitHub
parent 6bdb2f3d11
commit b1fd931cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1740 additions and 111 deletions

View file

@ -1,6 +1,8 @@
"""Insteon base entity."""
import logging
from pyinsteon import devices
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
@ -9,9 +11,11 @@ from homeassistant.helpers.dispatcher import (
from homeassistant.helpers.entity import Entity
from .const import (
DOMAIN,
SIGNAL_ADD_DEFAULT_LINKS,
SIGNAL_LOAD_ALDB,
SIGNAL_PRINT_ALDB,
SIGNAL_REMOVE_ENTITY,
SIGNAL_SAVE_DEVICES,
STATE_NAME_LABEL_MAP,
)
@ -74,6 +78,18 @@ class InsteonEntity(Entity):
"""Provide attributes for display on device card."""
return {"insteon_address": self.address, "insteon_group": self.group}
@property
def device_info(self):
"""Return device information."""
return {
"identifiers": {(DOMAIN, str(self._insteon_device.address))},
"name": f"{self._insteon_device.description} {self._insteon_device.address}",
"model": f"{self._insteon_device.model} (0x{self._insteon_device.cat:02x}, 0x{self._insteon_device.subcat:02x})",
"sw_version": f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}",
"manufacturer": "Smart Home",
"via_device": (DOMAIN, str(devices.modem.address)),
}
@callback
def async_entity_update(self, name, address, value, group):
"""Receive notification from transport that new data exists."""
@ -101,6 +117,20 @@ class InsteonEntity(Entity):
async_dispatcher_connect(
self.hass, default_links_signal, self._async_add_default_links
)
remove_signal = f"{self._insteon_device.address.id}_{SIGNAL_REMOVE_ENTITY}"
self.async_on_remove(
async_dispatcher_connect(self.hass, remove_signal, self.async_remove)
)
async def async_will_remove_from_hass(self):
"""Unsubscribe to INSTEON update events."""
_LOGGER.debug(
"Remove tracking updates for device %s group %d name %s",
self.address,
self.group,
self._insteon_device_group.name,
)
self._insteon_device_group.unsubscribe(self.async_entity_update)
async def _async_read_aldb(self, reload):
"""Call device load process and print to log."""