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>pull/33681/head
parent
b00b8ea0c1
commit
61b4d1e8de
|
@ -30,7 +30,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
_LOGGER.debug(
|
||||
"Adding device %s entity %s to Binary Sensor platform",
|
||||
device.address.hex,
|
||||
device.states[state_key].name,
|
||||
name,
|
||||
)
|
||||
|
||||
new_entity = InsteonBinarySensor(device, state_key)
|
||||
|
|
|
@ -55,21 +55,18 @@ class InsteonEntity(Entity):
|
|||
"""Return the name of the node (used for Entity_ID)."""
|
||||
# Set a base description
|
||||
description = self._insteon_device.description
|
||||
if self._insteon_device.description is None:
|
||||
if description is None:
|
||||
description = "Unknown Device"
|
||||
|
||||
# Get an extension label if there is one
|
||||
extension = self._get_label()
|
||||
if extension:
|
||||
extension = f" {extension}"
|
||||
name = f"{description} {self._insteon_device.address.human}{extension}"
|
||||
return name
|
||||
return f"{description} {self._insteon_device.address.human}{extension}"
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Provide attributes for display on device card."""
|
||||
attributes = {"insteon_address": self.address, "insteon_group": self.group}
|
||||
return attributes
|
||||
return {"insteon_address": self.address, "insteon_group": self.group}
|
||||
|
||||
@callback
|
||||
def async_entity_update(self, deviceid, group, val):
|
||||
|
|
|
@ -71,8 +71,7 @@ class IPDB:
|
|||
|
||||
def __iter__(self):
|
||||
"""Itterate through the INSTEON state types to HA platforms."""
|
||||
for product in self.states:
|
||||
yield product
|
||||
yield from self.states
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""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:
|
||||
hub_version = schema.get(CONF_HUB_VERSION)
|
||||
# Found hub_version but not ip_port
|
||||
if hub_version == 1:
|
||||
schema[CONF_IP_PORT] = 9761
|
||||
else:
|
||||
schema[CONF_IP_PORT] = 25105
|
||||
schema[CONF_IP_PORT] = 9761 if hub_version == 1 else 25105
|
||||
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
|
||||
|
||||
_LOGGER.debug(
|
||||
"Adding device %s entity %s to Switch platform",
|
||||
device.address.hex,
|
||||
device.states[state_key].name,
|
||||
"Adding device %s entity %s to Switch platform", device.address.hex, state_name,
|
||||
)
|
||||
|
||||
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()
|
||||
)
|
||||
schema = {CONF_ADDRESS: address.hex}
|
||||
if button != "":
|
||||
if button:
|
||||
schema[EVENT_CONF_BUTTON] = button
|
||||
if val:
|
||||
event = EVENT_BUTTON_ON
|
||||
else:
|
||||
event = EVENT_BUTTON_OFF
|
||||
event = EVENT_BUTTON_ON if val else EVENT_BUTTON_OFF
|
||||
_LOGGER.debug(
|
||||
"Firing event %s with address %s and button %s", event, address.hex, button
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue