diff --git a/homeassistant/components/konnected/binary_sensor.py b/homeassistant/components/konnected/binary_sensor.py index 2f21f8c15bd..d7c41337342 100644 --- a/homeassistant/components/konnected/binary_sensor.py +++ b/homeassistant/components/konnected/binary_sensor.py @@ -42,38 +42,12 @@ class KonnectedBinarySensor(BinarySensorEntity): def __init__(self, device_id, zone_num, data): """Initialize the Konnected binary sensor.""" self._data = data - self._device_id = device_id - self._zone_num = zone_num - self._state = self._data.get(ATTR_STATE) - self._device_class = self._data.get(CONF_TYPE) - self._unique_id = f"{device_id}-{zone_num}" - self._name = self._data.get(CONF_NAME) - - @property - def unique_id(self) -> str: - """Return the unique id.""" - return self._unique_id - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def is_on(self): - """Return the state of the sensor.""" - return self._state - - @property - def device_class(self): - """Return the device class.""" - return self._device_class - - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return DeviceInfo( - identifiers={(KONNECTED_DOMAIN, self._device_id)}, + self._attr_is_on = data.get(ATTR_STATE) + self._attr_device_class = data.get(CONF_TYPE) + self._attr_unique_id = f"{device_id}-{zone_num}" + self._attr_name = data.get(CONF_NAME) + self._attr_device_info = DeviceInfo( + identifiers={(KONNECTED_DOMAIN, device_id)}, ) async def async_added_to_hass(self) -> None: @@ -88,5 +62,5 @@ class KonnectedBinarySensor(BinarySensorEntity): @callback def async_set_state(self, state): """Update the sensor's state.""" - self._state = state + self._attr_is_on = state self.async_write_ha_state() diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index b341afa765f..3f203d5f3e8 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -111,9 +111,9 @@ class KonnectedSensor(SensorEntity): self._attr_unique_id = addr or f"{device_id}-{self._zone_num}-{description.key}" # set initial state if known at initialization - self._state = initial_state - if self._state: - self._state = round(float(self._state), 1) + self._attr_native_value = initial_state + if initial_state: + self._attr_native_value = round(float(initial_state), 1) # set entity name if given if name := self._data.get(CONF_NAME): @@ -122,11 +122,6 @@ class KonnectedSensor(SensorEntity): self._attr_device_info = DeviceInfo(identifiers={(KONNECTED_DOMAIN, device_id)}) - @property - def native_value(self): - """Return the state of the sensor.""" - return self._state - async def async_added_to_hass(self) -> None: """Store entity_id and register state change callback.""" entity_id_key = self._addr or self.entity_description.key @@ -139,7 +134,7 @@ class KonnectedSensor(SensorEntity): def async_set_state(self, state): """Update the sensor's state.""" if self.entity_description.key == "humidity": - self._state = int(float(state)) + self._attr_native_value = int(float(state)) else: - self._state = round(float(state), 1) + self._attr_native_value = round(float(state), 1) self.async_write_ha_state() diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index ba0dc62b606..18132a913ad 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -56,27 +56,13 @@ class KonnectedSwitch(SwitchEntity): self._momentary = self._data.get(CONF_MOMENTARY) self._pause = self._data.get(CONF_PAUSE) self._repeat = self._data.get(CONF_REPEAT) - self._state = self._boolean_state(self._data.get(ATTR_STATE)) - self._name = self._data.get(CONF_NAME) - self._unique_id = ( + self._attr_is_on = self._boolean_state(self._data.get(ATTR_STATE)) + self._attr_name = self._data.get(CONF_NAME) + self._attr_unique_id = ( f"{device_id}-{self._zone_num}-{self._momentary}-" f"{self._pause}-{self._repeat}" ) - - @property - def unique_id(self) -> str: - """Return the unique id.""" - return self._unique_id - - @property - def name(self): - """Return the name of the switch.""" - return self._name - - @property - def is_on(self): - """Return the status of the sensor.""" - return self._state + self._attr_device_info = DeviceInfo(identifiers={(KONNECTED_DOMAIN, device_id)}) @property def panel(self): @@ -84,11 +70,6 @@ class KonnectedSwitch(SwitchEntity): device_data = self.hass.data[KONNECTED_DOMAIN][CONF_DEVICES][self._device_id] return device_data.get("panel") - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return DeviceInfo(identifiers={(KONNECTED_DOMAIN, self._device_id)}) - @property def available(self) -> bool: """Return whether the panel is available.""" @@ -129,7 +110,7 @@ class KonnectedSwitch(SwitchEntity): return self._activation == STATE_HIGH def _set_state(self, state): - self._state = state + self._attr_is_on = state self.async_write_ha_state() _LOGGER.debug( "Setting status of %s actuator zone %s to %s",