Skip to content

Commit

Permalink
make Config no longer a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
caibinqing committed Aug 31, 2024
1 parent 6031279 commit 68a0bec
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 72 deletions.
7 changes: 4 additions & 3 deletions custom_components/ds_air/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {})
host = entry.data[CONF_HOST]
port = entry.data[CONF_PORT]
Expand All @@ -35,9 +35,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data[DOMAIN][CONF_GW] = gw
hass.data[DOMAIN][CONF_SCAN_INTERVAL] = scan_interval

Config.is_c611 = gw == DEFAULT_GW
config = Config()
config.is_c611 = gw == DEFAULT_GW

await hass.async_add_executor_job(Service.init, host, port, scan_interval)
await hass.async_add_executor_job(Service.init, host, port, scan_interval, config)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(update_listener))

Expand Down
6 changes: 4 additions & 2 deletions custom_components/ds_air/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ 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._device_info.alias == 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 Down Expand Up @@ -248,7 +250,7 @@ def current_temperature(self) -> float | None:
if self._link_cur_temp:
return self._attr_current_temperature
else:
if Config.is_c611:
if self._device_info.config.is_c611:
return None
else:
return self._device_info.status.current_temp / 10
Expand Down
4 changes: 1 addition & 3 deletions custom_components/ds_air/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ async def async_step_adjust_config(
{
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_GW, default=data[CONF_GW]): vol.In(GW_LIST),
vol.Required(
CONF_SCAN_INTERVAL, default=data[CONF_SCAN_INTERVAL]
): int,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/ds_air/ds_air_service/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EnumOutDoorRunCond,
EnumSwitch,
)
from .config import Config


class Device:
Expand Down Expand Up @@ -51,8 +52,9 @@ def __init__(


class AirCon(Device):
def __init__(self):
def __init__(self, config: Config):
super().__init__()
self.config = config
self.auto_dry_mode: int = 0
self.auto_mode: int = 0
self.bath_room: bool = False
Expand Down
Loading

0 comments on commit 68a0bec

Please sign in to comment.