Small code style improvements to Insteon integration (#33662)
* Small code style improvements to Insteon integration * Update homeassistant/components/insteon/utils.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b00b8ea0c1
commit
61b4d1e8de
6 changed files with 9 additions and 21 deletions
|
@ -30,7 +30,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Adding device %s entity %s to Binary Sensor platform",
|
"Adding device %s entity %s to Binary Sensor platform",
|
||||||
device.address.hex,
|
device.address.hex,
|
||||||
device.states[state_key].name,
|
name,
|
||||||
)
|
)
|
||||||
|
|
||||||
new_entity = InsteonBinarySensor(device, state_key)
|
new_entity = InsteonBinarySensor(device, state_key)
|
||||||
|
|
|
@ -55,21 +55,18 @@ class InsteonEntity(Entity):
|
||||||
"""Return the name of the node (used for Entity_ID)."""
|
"""Return the name of the node (used for Entity_ID)."""
|
||||||
# Set a base description
|
# Set a base description
|
||||||
description = self._insteon_device.description
|
description = self._insteon_device.description
|
||||||
if self._insteon_device.description is None:
|
if description is None:
|
||||||
description = "Unknown Device"
|
description = "Unknown Device"
|
||||||
|
|
||||||
# Get an extension label if there is one
|
# Get an extension label if there is one
|
||||||
extension = self._get_label()
|
extension = self._get_label()
|
||||||
if extension:
|
if extension:
|
||||||
extension = f" {extension}"
|
extension = f" {extension}"
|
||||||
name = f"{description} {self._insteon_device.address.human}{extension}"
|
return f"{description} {self._insteon_device.address.human}{extension}"
|
||||||
return name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Provide attributes for display on device card."""
|
"""Provide attributes for display on device card."""
|
||||||
attributes = {"insteon_address": self.address, "insteon_group": self.group}
|
return {"insteon_address": self.address, "insteon_group": self.group}
|
||||||
return attributes
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_entity_update(self, deviceid, group, val):
|
def async_entity_update(self, deviceid, group, val):
|
||||||
|
|
|
@ -71,8 +71,7 @@ class IPDB:
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Itterate through the INSTEON state types to HA platforms."""
|
"""Itterate through the INSTEON state types to HA platforms."""
|
||||||
for product in self.states:
|
yield from self.states
|
||||||
yield product
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Return a Home Assistant platform from an INSTEON state type."""
|
"""Return a Home Assistant platform from an INSTEON state type."""
|
||||||
|
|
|
@ -52,10 +52,7 @@ def set_default_port(schema: Dict) -> Dict:
|
||||||
if not ip_port:
|
if not ip_port:
|
||||||
hub_version = schema.get(CONF_HUB_VERSION)
|
hub_version = schema.get(CONF_HUB_VERSION)
|
||||||
# Found hub_version but not ip_port
|
# Found hub_version but not ip_port
|
||||||
if hub_version == 1:
|
schema[CONF_IP_PORT] = 9761 if hub_version == 1 else 25105
|
||||||
schema[CONF_IP_PORT] = 9761
|
|
||||||
else:
|
|
||||||
schema[CONF_IP_PORT] = 25105
|
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
state_name = device.states[state_key].name
|
state_name = device.states[state_key].name
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Adding device %s entity %s to Switch platform",
|
"Adding device %s entity %s to Switch platform", device.address.hex, state_name,
|
||||||
device.address.hex,
|
|
||||||
device.states[state_key].name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
new_entity = None
|
new_entity = None
|
||||||
|
|
|
@ -58,12 +58,9 @@ def register_new_device_callback(hass, config, insteon_modem):
|
||||||
"" if state_name == BUTTON_PRESSED_STATE_NAME else state_name[-1].lower()
|
"" if state_name == BUTTON_PRESSED_STATE_NAME else state_name[-1].lower()
|
||||||
)
|
)
|
||||||
schema = {CONF_ADDRESS: address.hex}
|
schema = {CONF_ADDRESS: address.hex}
|
||||||
if button != "":
|
if button:
|
||||||
schema[EVENT_CONF_BUTTON] = button
|
schema[EVENT_CONF_BUTTON] = button
|
||||||
if val:
|
event = EVENT_BUTTON_ON if val else EVENT_BUTTON_OFF
|
||||||
event = EVENT_BUTTON_ON
|
|
||||||
else:
|
|
||||||
event = EVENT_BUTTON_OFF
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Firing event %s with address %s and button %s", event, address.hex, button
|
"Firing event %s with address %s and button %s", event, address.hex, button
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue