Skip to content

Commit

Permalink
fix: modify
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Aug 10, 2024
1 parent 19f3a57 commit 278ef8a
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 19 deletions.
16 changes: 10 additions & 6 deletions custom_components/kocom_smart_home/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
api: KocomHomeAPI = KocomHomeAPI(hass)
await api.set_entry_and_initialize_devices(entry)

api = KocomHomeAPI(hass)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api

await api.initialize_devices(entry)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

entry.async_on_unload(entry.add_update_listener(_async_update_listener))

return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
hass.data[DOMAIN].pop(entry.entry_id)
return True
if unload_ok := await hass.config_entries.async_unload_platforms(
entry, PLATFORMS
):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok

async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
Expand Down
7 changes: 4 additions & 3 deletions custom_components/kocom_smart_home/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def __init__(self, hass) -> None:
"aircon": {}
}

async def set_entry_and_initialize_devices(self, entry):
"""Set entry data and initialize device states if necessary."""
async def initialize_devices(self, entry: Any):
"""Initialize the device and user credentials."""
self.entry = entry
self.user_credentials = self.entry.data.get("pairing_data", {})
if all(not value for value in self.device_settings.values()):
if not any(self.device_settings.values()):
await asyncio.gather(
self.update_device_state("light"),
self.update_device_state("concent"),
Expand All @@ -71,6 +71,7 @@ async def set_entry_and_initialize_devices(self, entry):
)

def set_user_credentials(self, data: dict):
"""Set user credentials."""
if len(data.keys()) == 3:
self.user_credentials["password"] = data["pwd"]
self.user_credentials["user_id"] = f"00000{str(data['zone'])}00{str(data['id'])}"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kocom_smart_home/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities_to_add.extend(
KocomClimate(coordinator, device)
for device in devices
if device["device_id"] not in hass.data[DOMAIN]
)

if entities_to_add:
Expand Down Expand Up @@ -124,6 +123,7 @@ def supported_features(self):
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
"Unique ID": self._device["device_id"],
"Device room": self._device["device_room"],
"Device type": self._device["device_type"],
"Registration Date": self._device["reg_date"],
Expand Down
4 changes: 2 additions & 2 deletions custom_components/kocom_smart_home/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

NAME = "Kocom Smart Home"
DOMAIN = "kocom_smart_home"
VERSION = "1.1.7"
VERSION = "1.1.8"

TIMEOUT_SEC = 10
TIMEOUT_SEC = 5

PLATFORMS = [
Platform.FAN,
Expand Down
8 changes: 6 additions & 2 deletions custom_components/kocom_smart_home/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities_to_add: list = [
KocomFan(coordinator, device)
for device in devices
if device["device_id"] not in hass.data[DOMAIN]
]

if entities_to_add:
Expand All @@ -38,6 +37,10 @@ def __init__(self, coordinator, device) -> None:
self._device = device
self._device_id = device["device_id"]
self._device_name = device["device_name"]

self._supported_features = FanEntityFeature.SET_SPEED
self._supported_features |= FanEntityFeature.TURN_ON
self._supported_features |= FanEntityFeature.TURN_OFF
super().__init__(coordinator)

@property
Expand All @@ -59,7 +62,7 @@ def is_on(self) -> bool:
@property
def supported_features(self) -> int:
"""Flag supported features."""
return FanEntityFeature.SET_SPEED
return self._supported_features

@property
def percentage(self) -> Optional[int]:
Expand Down Expand Up @@ -89,6 +92,7 @@ def speed_count(self) -> int:
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
"Unique ID": self._device["device_id"],
"Device room": self._device["device_room"],
"Device type": self._device["device_type"],
"Registration Date": self._device["reg_date"],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kocom_smart_home/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities_to_add.extend(
KocomLight(coordinator, device)
for device in devices
if device["device_id"] not in hass.data[DOMAIN]
)

if entities_to_add:
Expand Down Expand Up @@ -64,6 +63,7 @@ def supported_color_modes(self) -> set[ColorMode]:
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
"Unique ID": self._device["device_id"],
"Device room": self._device["device_room"],
"Device type": self._device["device_type"],
"Registration Date": self._device["reg_date"],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kocom_smart_home/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
],
"config_flow": true,
"iot_class": "cloud_polling",
"version": "1.1.7"
"version": "1.1.8"
}
2 changes: 1 addition & 1 deletion custom_components/kocom_smart_home/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities_to_add.extend(
KocomSensor(coordinator, device)
for device in devices
if device["device_id"] not in hass.data[DOMAIN]
)

if entities_to_add:
Expand Down Expand Up @@ -77,6 +76,7 @@ def state(self):
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
"Unique ID": self._device["device_id"],
"Device room": self._device["device_room"],
"Device type": self._device["device_type"],
"Registration Date": self._device["reg_date"],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kocom_smart_home/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities_to_add.extend(
KocomSwitch(coordinator, device)
for device in devices
if device["device_id"] not in hass.data[DOMAIN]
)

if entities_to_add:
Expand Down Expand Up @@ -62,6 +61,7 @@ def is_on(self) -> bool:
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
"Unique ID": self._device["device_id"],
"Device room": self._device["device_room"],
"Device type": self._device["device_type"],
"Registration Date": self._device["reg_date"],
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Kocom Smart Home",
"render_readme": true,
"homeassistant": "2023.8.4"
"homeassistant": "2024.4.0"
}
3 changes: 3 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### V1.1.8
- 수정

### V1.1.7
- 환기 오류 수정
- 중복 엔티티 등록 체크
Expand Down

0 comments on commit 278ef8a

Please sign in to comment.