优化设备添加流程

This commit is contained in:
unknown
2023-09-03 22:15:41 +08:00
parent fc82b6de79
commit faae480fd8
7 changed files with 175 additions and 99 deletions

View File

@@ -18,7 +18,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
device_id = config_entry.data.get(CONF_DEVICE_ID)
device = hass.data[DOMAIN][DEVICES].get(device_id)
binary_sensors = []
sensor = MideaDeviceStatusSensor(device, "online")
sensor = MideaDeviceStatusSensor(device, "status")
binary_sensors.append(sensor)
async_add_entities(binary_sensors)
@@ -32,6 +32,14 @@ class MideaDeviceStatusSensor(MideaEntity):
def state(self):
return STATE_ON if self._device.connected else STATE_OFF
@property
def name(self):
return f"{self._device_name} Status"
@property
def icon(self):
return "mdi:devices"
@property
def is_on(self):
return self.state == STATE_ON
@@ -46,8 +54,6 @@ class MideaDeviceStatusSensor(MideaEntity):
def update_state(self, status):
try:
_LOGGER.debug("=" * 50)
self.schedule_update_ha_state()
_LOGGER.debug("-" * 50)
except Exception as e:
pass