From 559105ff29cb43ce006466dc3c9b757137b6c28e Mon Sep 17 00:00:00 2001 From: Necroneco Date: Tue, 20 Aug 2024 13:11:29 +0800 Subject: [PATCH] has_entity_name --- custom_components/ds_air/climate.py | 13 +- custom_components/ds_air/config_flow.py | 111 +++++++----------- .../ds_air/ds_air_service/service.py | 2 +- 3 files changed, 53 insertions(+), 73 deletions(-) diff --git a/custom_components/ds_air/climate.py b/custom_components/ds_air/climate.py index d9e1c5d..88adaf8 100644 --- a/custom_components/ds_air/climate.py +++ b/custom_components/ds_air/climate.py @@ -25,7 +25,8 @@ CONF_PORT, MAJOR_VERSION, MINOR_VERSION, - PRECISION_TENTHS, UnitOfTemperature, + PRECISION_TENTHS, + UnitOfTemperature, ) from homeassistant.core import Event, HomeAssistant from homeassistant.helpers import config_validation as cv @@ -39,7 +40,8 @@ FAN_DIRECTION_LIST, MANUFACTURER, get_action_name, - get_air_flow_enum, get_air_flow_name, + get_air_flow_enum, + get_air_flow_name, get_fan_direction_enum, get_fan_direction_name, get_mode_name, @@ -83,7 +85,7 @@ async def async_setup_entry( if link is not None: for i in link: climate_name = i.get("climate") - if climate := next(c for c in climates if c.name == climate_name): + if climate := next(c for c in climates if c._device_info.alias == climate_name): if temp_entity_id := i.get("sensor_temp"): sensor_temp_map.setdefault(temp_entity_id, []).append(climate) climate.linked_temp_entity_id = temp_entity_id @@ -110,6 +112,8 @@ class DsAir(ClimateEntity): """Representation of a Daikin climate device.""" # Entity Properties + _attr_has_entity_name: bool = True + _attr_name: str | None = None _attr_should_poll: bool = False # Climate Properties @@ -132,7 +136,6 @@ def __init__(self, aircon: AirCon): _log(str(aircon.__dict__)) _log(str(aircon.status.__dict__)) """Initialize the climate device.""" - self._attr_name = aircon.alias self._device_info = aircon self._attr_unique_id = aircon.unique_id self.linked_temp_entity_id: str | None = None @@ -143,7 +146,7 @@ def __init__(self, aircon: AirCon): self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self.unique_id)}, - name=f"空调{self._attr_name}", + name=aircon.alias, manufacturer=MANUFACTURER, ) diff --git a/custom_components/ds_air/config_flow.py b/custom_components/ds_air/config_flow.py index de42514..8d18cc4 100644 --- a/custom_components/ds_air/config_flow.py +++ b/custom_components/ds_air/config_flow.py @@ -145,73 +145,50 @@ async def async_step_adjust_config( return self.async_create_entry(title="", data={}) else: self.user_input["_invaild"] = True - if CONF_SENSORS: - return self.async_show_form( - step_id="adjust_config", - data_schema=vol.Schema( - { - vol.Required( - CONF_HOST, default=self.config_entry.data[CONF_HOST] - ): str, - vol.Required( - CONF_PORT, default=self.config_entry.data[CONF_PORT] - ): int, - vol.Required( - CONF_GW, default=self.config_entry.data[CONF_GW] - ): vol.In(GW_LIST), - vol.Required( - CONF_SCAN_INTERVAL, - default=self.config_entry.data[CONF_SCAN_INTERVAL], - ): int, - vol.Required(CONF_SENSORS, default=True): bool, - vol.Required( - "temp", default=self.config_entry.data["temp"] - ): bool, - vol.Required( - "humidity", default=self.config_entry.data["humidity"] - ): bool, - vol.Required( - "pm25", default=self.config_entry.data["pm25"] - ): bool, - vol.Required( - "co2", default=self.config_entry.data["co2"] - ): bool, - vol.Required( - "tvoc", default=self.config_entry.data["tvoc"] - ): bool, - vol.Required( - "voc", default=self.config_entry.data["voc"] - ): bool, - vol.Required( - "hcho", default=self.config_entry.data["hcho"] - ): bool, - } - ), - errors=errors, - ) - else: - return self.async_show_form( - step_id="adjust_config", - data_schema=vol.Schema( - { - vol.Required( - CONF_HOST, default=self.config_entry.data[CONF_HOST] - ): str, - vol.Required( - CONF_PORT, default=self.config_entry.data[CONF_PORT] - ): int, - vol.Required( - CONF_GW, default=self.config_entry.data[CONF_GW] - ): vol.In(GW_LIST), - vol.Required( - CONF_SCAN_INTERVAL, - default=self.config_entry.data[CONF_SCAN_INTERVAL], - ): int, - vol.Required(CONF_SENSORS, default=False): bool, - } - ), - errors=errors, - ) + data = self.config_entry.data + # if CONF_SENSORS: + return self.async_show_form( + step_id="adjust_config", + data_schema=vol.Schema( + { + vol.Required(CONF_HOST, default=data[CONF_HOST]): str, + vol.Required(CONF_PORT, default=data[CONF_PORT]): int, + vol.Required(CONF_GW, default=data[CONF_GW]): vol.In( + GW_LIST + ), + vol.Required( + CONF_SCAN_INTERVAL, default=data[CONF_SCAN_INTERVAL] + ): int, + vol.Required(CONF_SENSORS, default=True): bool, + vol.Required("temp", default=data["temp"]): bool, + vol.Required("humidity", default=data["humidity"]): bool, + vol.Required("pm25", default=data["pm25"]): bool, + vol.Required("co2", default=data["co2"]): bool, + vol.Required("tvoc", default=data["tvoc"]): bool, + vol.Required("voc", default=data["voc"]): bool, + vol.Required("hcho", default=data["hcho"]): bool, + } + ), + errors=errors, + ) + # else: + # return self.async_show_form( + # step_id="adjust_config", + # data_schema=vol.Schema( + # { + # vol.Required(CONF_HOST, default=data[CONF_HOST]): str, + # vol.Required(CONF_PORT, default=data[CONF_PORT]): int, + # vol.Required(CONF_GW, default=data[CONF_GW]): vol.In( + # GW_LIST + # ), + # vol.Required( + # CONF_SCAN_INTERVAL, default=data[CONF_SCAN_INTERVAL] + # ): int, + # vol.Required(CONF_SENSORS, default=False): bool, + # } + # ), + # errors=errors, + # ) async def async_step_bind_sensors( self, user_input: dict[str, Any] | None = None diff --git a/custom_components/ds_air/ds_air_service/service.py b/custom_components/ds_air/ds_air_service/service.py index 70017bd..9f0392c 100644 --- a/custom_components/ds_air/ds_air_service/service.py +++ b/custom_components/ds_air/ds_air_service/service.py @@ -212,7 +212,7 @@ def destroy(): Service._ready = False @staticmethod - def get_aircons(): + def get_aircons() -> list[AirCon]: aircons = [] if Service._new_aircons is not None: aircons += Service._new_aircons