Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call async update ha state with force #53

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions custom_components/winix/device_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def async_ensure_on(self) -> None:
if not self._on:
self._on = True

self._logger.debug("%s: Turning on", self._alias)
self._logger.debug("%s => turned on", self._alias)
await self._driver.turn_on()

async def async_turn_on(self) -> None:
Expand All @@ -151,7 +151,7 @@ async def async_turn_off(self) -> None:
if self._on:
self._on = False

self._logger.debug("%s: Turning off", self._alias)
self._logger.debug("%s => turned off", self._alias)
await self._driver.turn_off()

async def async_auto(self) -> None:
Expand All @@ -171,7 +171,7 @@ async def async_auto(self) -> None:
ATTR_AIRFLOW
] = AIRFLOW_LOW # Something other than AIRFLOW_SLEEP

self._logger.debug("%s: Setting auto mode", self._alias)
self._logger.debug("%s => set mode=auto", self._alias)
await self._driver.auto()

async def async_plasmawave_on(self, force: bool = False) -> None:
Expand All @@ -181,7 +181,7 @@ async def async_plasmawave_on(self, force: bool = False) -> None:
self._plasma_on = True
self._state[ATTR_PLASMA] = ON_VALUE

self._logger.debug("%s: Turning plasmawave on", self._alias)
self._logger.debug("%s => set plasmawave=on", self._alias)
await self._driver.plasmawave_on()

async def async_plasmawave_off(self, force: bool = False) -> None:
Expand All @@ -191,7 +191,7 @@ async def async_plasmawave_off(self, force: bool = False) -> None:
self._plasma_on = False
self._state[ATTR_PLASMA] = OFF_VALUE

self._logger.debug("%s: Turning plasmawave off", self._alias)
self._logger.debug("%s => set plasmawave=off", self._alias)
await self._driver.plasmawave_off()

async def async_manual(self) -> None:
Expand All @@ -206,7 +206,7 @@ async def async_manual(self) -> None:
ATTR_AIRFLOW
] = AIRFLOW_LOW # Something other than AIRFLOW_SLEEP

self._logger.debug("%s: Setting manual mode", self._alias)
self._logger.debug("%s => set mode=manual", self._alias)
await self._driver.manual()

async def async_sleep(self) -> None:
Expand All @@ -219,7 +219,7 @@ async def async_sleep(self) -> None:
self._state[ATTR_AIRFLOW] = AIRFLOW_SLEEP
self._state[ATTR_MODE] = MODE_MANUAL

self._logger.debug("%s: Setting sleep mode", self._alias)
self._logger.debug("%s => set mode=sleep", self._alias)
await self._driver.sleep()

async def async_set_speed(self, speed) -> None:
Expand All @@ -232,7 +232,7 @@ async def async_set_speed(self, speed) -> None:
await self.async_ensure_on()
await self.async_manual()

self._logger.debug("%s: Updated speed to '%s'", self._alias, speed)
self._logger.debug("%s => set speed=%s", self._alias, speed)
await getattr(self._driver, speed)()

async def async_set_preset_mode(self, preset_mode: str) -> None:
Expand All @@ -252,7 +252,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
return

await self.async_ensure_on()
self._logger.debug("Setting mode to '%s'", preset_mode)
self._logger.debug("%s => set mode=%s", self._alias, preset_mode)

if preset_mode == PRESET_MODE_SLEEP:
await self.async_sleep()
Expand Down
15 changes: 7 additions & 8 deletions custom_components/winix/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def async_set_percentage(self, percentage: int) -> None:
percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, percentage)
)

await self.async_update_ha_state() # Update state without forcing a refresh
await self.async_update_ha_state(True) # Update state

async def async_turn_on(
self,
Expand All @@ -226,28 +226,27 @@ async def async_turn_on(

if percentage:
await self.async_set_percentage(percentage)
return
if preset_mode:
await self._wrapper.async_set_preset_mode(preset_mode)
else:
await self._wrapper.async_turn_on()

await self.async_update_ha_state()
await self.async_update_ha_state(True)

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the purifier."""
await self._wrapper.async_turn_off()
await self.async_update_ha_state()
await self.async_update_ha_state(True)

async def async_plasmawave_on(self) -> None:
"""Turn on plasma wave."""
await self._wrapper.async_plasmawave_on()
await self.async_update_ha_state()
await self.async_update_ha_state(True)

async def async_plasmawave_off(self) -> None:
"""Turn off plasma wave."""
await self._wrapper.async_plasmawave_off()
await self.async_update_ha_state()
await self.async_update_ha_state(True)

async def async_plasmawave_toggle(self) -> None:
"""Toggle plasma wave."""
Expand All @@ -257,9 +256,9 @@ async def async_plasmawave_toggle(self) -> None:
else:
await self._wrapper.async_plasmawave_on()

await self.async_update_ha_state()
await self.async_update_ha_state(True)

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
await self._wrapper.async_set_preset_mode(preset_mode)
await self.async_update_ha_state()
await self.async_update_ha_state(True)
12 changes: 12 additions & 0 deletions custom_components/winix/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@

_LOGGER = logging.getLogger(__name__)

# category_keys = {
# "power": "A02",
# "mode": "A03",
# "airflow": "A04",
# "aqi": "A05",
# "plasma": "A07",
# "filter_hour": "A21",
# "air_quality": "S07",
# "air_qvalue": "S08",
# "ambient_light": "S14",
# }


class WinixEntity(CoordinatorEntity):
"""Represents a Winix entity."""
Expand Down