Skip to content

Commit

Permalink
Rebuild code for easier maintenance + sensors adds
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredzxda authored Jun 23, 2023
1 parent 8d5a87f commit 110e2da
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 133 deletions.
4 changes: 4 additions & 0 deletions custom_components/aldes/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
"X": "Guest",
"Z": "Air Prog",
}
POLLUANTS = {
"hr": "Humidity",
"co2": "CO2",
}
30 changes: 15 additions & 15 deletions custom_components/aldes/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def device_info(self):
@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{DOMAIN}_{self.product_serial_number}_mode"
return f"{FRIENDLY_NAMES[self.reference]}_{self.product_serial_number}_mode"

@property
def name(self):
Expand All @@ -87,19 +87,19 @@ def current_option(self) -> str:
async def async_select_option(self, option: str) -> None:
"""Set mode."""
await self.coordinator.api.set_mode(self.modem, option)
self._mode = option
await self.coordinator.async_request_refresh()
self._handle_coordinator_update()

@callback
def _handle_coordinator_update(self) -> None:
"""Update attributes when the coordinator updates."""
self._async_update_attrs()
super()._handle_coordinator_update()

@callback
def _async_update_attrs(self) -> None:
"""Update select attributes."""
for product in self.coordinator.data:
for data_line in product["indicators"][0:]:
if data_line["type"] == "MODE":
self._mode = MODES_TEXT[data_line["value"]]
# @callback
# def _handle_coordinator_update(self) -> None:
# """Update attributes when the coordinator updates."""
# self._async_update_attrs()
# super()._handle_coordinator_update()

# @callback
# def _async_update_attrs(self) -> None:
# """Update select attributes."""
# for product in self.coordinator.data:
# for data_line in product["indicators"][0:]:
# if data_line["type"] == "MODE":
# self._mode = MODES_TEXT[data_line["value"]]
Loading

0 comments on commit 110e2da

Please sign in to comment.