Use a single source of data for switchbot (#84215)

This commit is contained in:
J. Nick Koston 2022-12-19 07:47:42 -10:00 committed by GitHub
parent 6e612a45ff
commit 7c13e7cdfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 55 deletions

View file

@ -89,11 +89,8 @@ async def async_setup_entry(
"""Set up Switchbot sensor based on a config entry."""
coordinator: SwitchbotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
entities = [
SwitchBotSensor(
coordinator,
sensor,
)
for sensor in coordinator.data["data"]
SwitchBotSensor(coordinator, sensor)
for sensor in coordinator.device.parsed_data
if sensor in SENSOR_TYPES
]
entities.append(SwitchbotRSSISensor(coordinator, "rssi"))
@ -117,7 +114,7 @@ class SwitchBotSensor(SwitchbotEntity, SensorEntity):
@property
def native_value(self) -> str | int | None:
"""Return the state of the sensor."""
return self.data["data"][self._sensor]
return self.parsed_data[self._sensor]
class SwitchbotRSSISensor(SwitchBotSensor):