Skip to content

Commit

Permalink
has_entity_name
Browse files Browse the repository at this point in the history
  • Loading branch information
caibinqing committed Aug 20, 2024
1 parent e504da7 commit 559105f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 73 deletions.
13 changes: 8 additions & 5 deletions custom_components/ds_air/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
)

Expand Down
111 changes: 44 additions & 67 deletions custom_components/ds_air/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ds_air/ds_air_service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 559105f

Please sign in to comment.