From 61b4d1e8de6e2db03d3f546c2666bfb3d08466e9 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 5 Apr 2020 02:58:10 +0200 Subject: [PATCH] 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 Co-authored-by: Martin Hjelmare --- homeassistant/components/insteon/binary_sensor.py | 2 +- homeassistant/components/insteon/insteon_entity.py | 9 +++------ homeassistant/components/insteon/ipdb.py | 3 +-- homeassistant/components/insteon/schemas.py | 5 +---- homeassistant/components/insteon/switch.py | 4 +--- homeassistant/components/insteon/utils.py | 7 ++----- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/insteon/binary_sensor.py b/homeassistant/components/insteon/binary_sensor.py index 395c0a3ac20..b96feb21831 100644 --- a/homeassistant/components/insteon/binary_sensor.py +++ b/homeassistant/components/insteon/binary_sensor.py @@ -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) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 19f3344fb81..b453cad2e07 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -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): diff --git a/homeassistant/components/insteon/ipdb.py b/homeassistant/components/insteon/ipdb.py index 1618518a0eb..6aba40d6df9 100644 --- a/homeassistant/components/insteon/ipdb.py +++ b/homeassistant/components/insteon/ipdb.py @@ -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.""" diff --git a/homeassistant/components/insteon/schemas.py b/homeassistant/components/insteon/schemas.py index 20399195365..e3f2644ac56 100644 --- a/homeassistant/components/insteon/schemas.py +++ b/homeassistant/components/insteon/schemas.py @@ -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 diff --git a/homeassistant/components/insteon/switch.py b/homeassistant/components/insteon/switch.py index eec7874c7fb..c88d31d2f91 100644 --- a/homeassistant/components/insteon/switch.py +++ b/homeassistant/components/insteon/switch.py @@ -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 diff --git a/homeassistant/components/insteon/utils.py b/homeassistant/components/insteon/utils.py index 339189d3564..26768936291 100644 --- a/homeassistant/components/insteon/utils.py +++ b/homeassistant/components/insteon/utils.py @@ -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 )