Use shorthand attributes in Konnected (#99580)
This commit is contained in:
parent
c49f086790
commit
447a9f4aad
3 changed files with 17 additions and 67 deletions
|
@ -42,38 +42,12 @@ class KonnectedBinarySensor(BinarySensorEntity):
|
||||||
def __init__(self, device_id, zone_num, data):
|
def __init__(self, device_id, zone_num, data):
|
||||||
"""Initialize the Konnected binary sensor."""
|
"""Initialize the Konnected binary sensor."""
|
||||||
self._data = data
|
self._data = data
|
||||||
self._device_id = device_id
|
self._attr_is_on = data.get(ATTR_STATE)
|
||||||
self._zone_num = zone_num
|
self._attr_device_class = data.get(CONF_TYPE)
|
||||||
self._state = self._data.get(ATTR_STATE)
|
self._attr_unique_id = f"{device_id}-{zone_num}"
|
||||||
self._device_class = self._data.get(CONF_TYPE)
|
self._attr_name = data.get(CONF_NAME)
|
||||||
self._unique_id = f"{device_id}-{zone_num}"
|
self._attr_device_info = DeviceInfo(
|
||||||
self._name = self._data.get(CONF_NAME)
|
identifiers={(KONNECTED_DOMAIN, device_id)},
|
||||||
|
|
||||||
@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)},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
|
@ -88,5 +62,5 @@ class KonnectedBinarySensor(BinarySensorEntity):
|
||||||
@callback
|
@callback
|
||||||
def async_set_state(self, state):
|
def async_set_state(self, state):
|
||||||
"""Update the sensor's state."""
|
"""Update the sensor's state."""
|
||||||
self._state = state
|
self._attr_is_on = state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
|
@ -111,9 +111,9 @@ class KonnectedSensor(SensorEntity):
|
||||||
self._attr_unique_id = addr or f"{device_id}-{self._zone_num}-{description.key}"
|
self._attr_unique_id = addr or f"{device_id}-{self._zone_num}-{description.key}"
|
||||||
|
|
||||||
# set initial state if known at initialization
|
# set initial state if known at initialization
|
||||||
self._state = initial_state
|
self._attr_native_value = initial_state
|
||||||
if self._state:
|
if initial_state:
|
||||||
self._state = round(float(self._state), 1)
|
self._attr_native_value = round(float(initial_state), 1)
|
||||||
|
|
||||||
# set entity name if given
|
# set entity name if given
|
||||||
if name := self._data.get(CONF_NAME):
|
if name := self._data.get(CONF_NAME):
|
||||||
|
@ -122,11 +122,6 @@ class KonnectedSensor(SensorEntity):
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(identifiers={(KONNECTED_DOMAIN, device_id)})
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Store entity_id and register state change callback."""
|
"""Store entity_id and register state change callback."""
|
||||||
entity_id_key = self._addr or self.entity_description.key
|
entity_id_key = self._addr or self.entity_description.key
|
||||||
|
@ -139,7 +134,7 @@ class KonnectedSensor(SensorEntity):
|
||||||
def async_set_state(self, state):
|
def async_set_state(self, state):
|
||||||
"""Update the sensor's state."""
|
"""Update the sensor's state."""
|
||||||
if self.entity_description.key == "humidity":
|
if self.entity_description.key == "humidity":
|
||||||
self._state = int(float(state))
|
self._attr_native_value = int(float(state))
|
||||||
else:
|
else:
|
||||||
self._state = round(float(state), 1)
|
self._attr_native_value = round(float(state), 1)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
|
@ -56,27 +56,13 @@ class KonnectedSwitch(SwitchEntity):
|
||||||
self._momentary = self._data.get(CONF_MOMENTARY)
|
self._momentary = self._data.get(CONF_MOMENTARY)
|
||||||
self._pause = self._data.get(CONF_PAUSE)
|
self._pause = self._data.get(CONF_PAUSE)
|
||||||
self._repeat = self._data.get(CONF_REPEAT)
|
self._repeat = self._data.get(CONF_REPEAT)
|
||||||
self._state = self._boolean_state(self._data.get(ATTR_STATE))
|
self._attr_is_on = self._boolean_state(self._data.get(ATTR_STATE))
|
||||||
self._name = self._data.get(CONF_NAME)
|
self._attr_name = self._data.get(CONF_NAME)
|
||||||
self._unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{device_id}-{self._zone_num}-{self._momentary}-"
|
f"{device_id}-{self._zone_num}-{self._momentary}-"
|
||||||
f"{self._pause}-{self._repeat}"
|
f"{self._pause}-{self._repeat}"
|
||||||
)
|
)
|
||||||
|
self._attr_device_info = DeviceInfo(identifiers={(KONNECTED_DOMAIN, device_id)})
|
||||||
@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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def panel(self):
|
def panel(self):
|
||||||
|
@ -84,11 +70,6 @@ class KonnectedSwitch(SwitchEntity):
|
||||||
device_data = self.hass.data[KONNECTED_DOMAIN][CONF_DEVICES][self._device_id]
|
device_data = self.hass.data[KONNECTED_DOMAIN][CONF_DEVICES][self._device_id]
|
||||||
return device_data.get("panel")
|
return device_data.get("panel")
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info."""
|
|
||||||
return DeviceInfo(identifiers={(KONNECTED_DOMAIN, self._device_id)})
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return whether the panel is available."""
|
"""Return whether the panel is available."""
|
||||||
|
@ -129,7 +110,7 @@ class KonnectedSwitch(SwitchEntity):
|
||||||
return self._activation == STATE_HIGH
|
return self._activation == STATE_HIGH
|
||||||
|
|
||||||
def _set_state(self, state):
|
def _set_state(self, state):
|
||||||
self._state = state
|
self._attr_is_on = state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting status of %s actuator zone %s to %s",
|
"Setting status of %s actuator zone %s to %s",
|
||||||
|
|
Loading…
Add table
Reference in a new issue