Cleanup and improve Plugwise merges (#36406)

* Remove period from logging messages

* Save indentation using guard clauses

* Typo

* Walk other files

* Rewalk all files

* Not cleanup, but adding indicatd missing measurements

* Revert new sensors
This commit is contained in:
Tom 2020-06-04 08:18:46 +02:00 committed by GitHub
parent 08e85696c1
commit 48d1bc7c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 75 deletions

View File

@ -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

View File

@ -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()

View File

@ -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:

View File

@ -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

View File

@ -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