diff --git a/homeassistant/components/plugwise/__init__.py b/homeassistant/components/plugwise/__init__.py index a0b98f9d1c0..efb97f51c41 100644 --- a/homeassistant/components/plugwise/__init__.py +++ b/homeassistant/components/plugwise/__init__.py @@ -58,10 +58,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.error("Timeout while connecting to Smile") raise ConfigEntryNotReady + update_interval = timedelta(seconds=60) if api.smile_type == "power": update_interval = timedelta(seconds=10) - else: - update_interval = timedelta(seconds=60) async def async_update_data(): """Update data via API endpoint.""" @@ -102,9 +101,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: sw_version=api.smile_version[0], ) - platforms = ALL_PLATFORMS - single_master_thermostat = api.single_master_thermostat() + + platforms = ALL_PLATFORMS if single_master_thermostat is None: platforms = SENSOR_PLATFORMS @@ -165,8 +164,6 @@ class SmileGateway(Entity): @property def name(self): """Return the name of the entity, if any.""" - if not self._name: - return None return self._name @property diff --git a/homeassistant/components/plugwise/binary_sensor.py b/homeassistant/components/plugwise/binary_sensor.py index a2156cd37f9..d6b6424c7ce 100644 --- a/homeassistant/components/plugwise/binary_sensor.py +++ b/homeassistant/components/plugwise/binary_sensor.py @@ -26,20 +26,24 @@ async def async_setup_entry(hass, config_entry, async_add_entities): all_devices = api.get_all_devices() for dev_id, device_properties in all_devices.items(): - if device_properties["class"] == "heater_central": - data = api.get_device_data(dev_id) - for binary_sensor, dummy in BINARY_SENSOR_MAP.items(): - if binary_sensor in data: - entities.append( - PwBinarySensor( - api, - coordinator, - device_properties["name"], - binary_sensor, - dev_id, - device_properties["class"], - ) - ) + if device_properties["class"] != "heater_central": + continue + + data = api.get_device_data(dev_id) + for binary_sensor, dummy in BINARY_SENSOR_MAP.items(): + if binary_sensor not in data: + continue + + entities.append( + PwBinarySensor( + api, + coordinator, + device_properties["name"], + binary_sensor, + dev_id, + device_properties["class"], + ) + ) async_add_entities(entities, True) @@ -74,23 +78,26 @@ class PwBinarySensor(SmileSensor, BinarySensorEntity): data = self._api.get_device_data(self._dev_id) if not data: - _LOGGER.error("Received no data for device %s.", self._binary_sensor) + _LOGGER.error("Received no data for device %s", self._binary_sensor) self.async_write_ha_state() return - if self._binary_sensor in data: - self._is_on = data[self._binary_sensor] + if self._binary_sensor not in data: + self.async_write_ha_state() + return - self._state = STATE_OFF + self._is_on = data[self._binary_sensor] + + self._state = STATE_OFF + if self._binary_sensor == "dhw_state": + self._icon = FLOW_OFF_ICON + if self._binary_sensor == "slave_boiler_state": + self._icon = IDLE_ICON + if self._is_on: + self._state = STATE_ON if self._binary_sensor == "dhw_state": - self._icon = FLOW_OFF_ICON + self._icon = FLOW_ON_ICON if self._binary_sensor == "slave_boiler_state": - self._icon = IDLE_ICON - if self._is_on: - self._state = STATE_ON - if self._binary_sensor == "dhw_state": - self._icon = FLOW_ON_ICON - if self._binary_sensor == "slave_boiler_state": - self._icon = FLAME_ICON + self._icon = FLAME_ICON self.async_write_ha_state() diff --git a/homeassistant/components/plugwise/climate.py b/homeassistant/components/plugwise/climate.py index 42d4aa462b6..e6ee850c09d 100644 --- a/homeassistant/components/plugwise/climate.py +++ b/homeassistant/components/plugwise/climate.py @@ -238,10 +238,9 @@ class PwThermostat(SmileGateway, ClimateEntity): self._schema_names = climate_data["available_schedules"] if "selected_schedule" in climate_data: self._selected_schema = climate_data["selected_schedule"] + self._schema_status = False if self._selected_schema is not None: self._schema_status = True - else: - self._schema_status = False if "last_used" in climate_data: self._last_active_schema = climate_data["last_used"] if "presets" in climate_data: diff --git a/homeassistant/components/plugwise/sensor.py b/homeassistant/components/plugwise/sensor.py index eabb5c6655f..08ba3595fcd 100644 --- a/homeassistant/components/plugwise/sensor.py +++ b/homeassistant/components/plugwise/sensor.py @@ -153,52 +153,53 @@ async def async_setup_entry(hass, config_entry, async_add_entities): **ENERGY_SENSOR_MAP, **MISC_SENSOR_MAP, }.items(): - if sensor in data: - if data[sensor] is None: - continue + if data.get(sensor) is None: + continue - if "power" in device_properties["types"]: - model = None + if "power" in device_properties["types"]: + model = None - if "plug" in device_properties["types"]: - model = "Metered Switch" + if "plug" in device_properties["types"]: + model = "Metered Switch" - entities.append( - PwPowerSensor( - api, - coordinator, - device_properties["name"], - dev_id, - sensor, - sensor_type, - model, - ) + entities.append( + PwPowerSensor( + api, + coordinator, + device_properties["name"], + dev_id, + sensor, + sensor_type, + model, ) - else: - entities.append( - PwThermostatSensor( - api, - coordinator, - device_properties["name"], - dev_id, - sensor, - sensor_type, - ) + ) + else: + entities.append( + PwThermostatSensor( + api, + coordinator, + device_properties["name"], + dev_id, + sensor, + sensor_type, ) + ) if single_thermostat is False: for state in INDICATE_ACTIVE_LOCAL_DEVICE: - if state in data: - entities.append( - PwAuxDeviceSensor( - api, - coordinator, - device_properties["name"], - dev_id, - DEVICE_STATE, - ) + if state not in data: + continue + + entities.append( + PwAuxDeviceSensor( + api, + coordinator, + device_properties["name"], + dev_id, + DEVICE_STATE, ) - break + ) + break async_add_entities(entities, True) @@ -260,7 +261,7 @@ class PwThermostatSensor(SmileSensor, Entity): data = self._api.get_device_data(self._dev_id) if not data: - _LOGGER.error("Received no data for device %s.", self._entity_name) + _LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return @@ -297,7 +298,7 @@ class PwAuxDeviceSensor(SmileSensor, Entity): data = self._api.get_device_data(self._dev_id) if not data: - _LOGGER.error("Received no data for device %s.", self._entity_name) + _LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return @@ -341,7 +342,7 @@ class PwPowerSensor(SmileSensor, Entity): data = self._api.get_device_data(self._dev_id) if not data: - _LOGGER.error("Received no data for device %s.", self._entity_name) + _LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return diff --git a/homeassistant/components/plugwise/switch.py b/homeassistant/components/plugwise/switch.py index 50b704e36ac..bd831e2f9aa 100644 --- a/homeassistant/components/plugwise/switch.py +++ b/homeassistant/components/plugwise/switch.py @@ -74,7 +74,7 @@ class PwSwitch(SmileGateway, SwitchEntity): data = self._api.get_device_data(self._dev_id) if not data: - _LOGGER.error("Received no data for device %s.", self._name) + _LOGGER.error("Received no data for device %s", self._name) self.async_write_ha_state() return