Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def _init_client() -> Client:

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

entry.async_on_unload(entry.add_update_listener(async_update_options))

return True


Expand All @@ -220,6 +222,13 @@ async def async_unload_entry(
return True


async def async_update_options(
hass: HomeAssistant, entry: GoogleGenerativeAIConfigEntry
) -> None:
"""Update options."""
await hass.config_entries.async_reload(entry.entry_id)


async def async_migrate_integration(hass: HomeAssistant) -> None:
"""Migrate integration entry structure."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ async def async_added_to_hass(self) -> None:
self.hass, "conversation", self.entry.entry_id, self.entity_id
)
conversation.async_set_agent(self.hass, self.entry, self)
self.entry.async_on_unload(
self.entry.add_update_listener(self._async_entry_update_listener)
)

async def async_will_remove_from_hass(self) -> None:
"""When entity will be removed from Home Assistant."""
Expand Down Expand Up @@ -103,10 +100,3 @@ async def _async_handle_message(
conversation_id=chat_log.conversation_id,
continue_conversation=chat_log.continue_conversation,
)

async def _async_entry_update_listener(
self, hass: HomeAssistant, entry: ConfigEntry
) -> None:
"""Handle options update."""
# Reload as we update device info + entity name + supported features
await hass.config_entries.async_reload(entry.entry_id)
42 changes: 25 additions & 17 deletions homeassistant/components/vesync/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,36 @@ def extra_state_attributes(self) -> dict[str, Any]:
return attr

def set_percentage(self, percentage: int) -> None:
"""Set the speed of the device."""
"""Set the speed of the device.

If percentage is 0, turn off the fan. Otherwise, ensure the fan is on,
set manual mode if needed, and set the speed.
"""
device_type = SKU_TO_BASE_DEVICE[self.device.device_type]
speed_range = SPEED_RANGE[device_type]

if percentage == 0:
success = self.device.turn_off()
if not success:
# Turning off is a special case: do not set speed or mode
if not self.device.turn_off():
raise HomeAssistantError("An error occurred while turning off.")
elif not self.device.is_on:
success = self.device.turn_on()
if not success:
self.schedule_update_ha_state()
return

# If the fan is off, turn it on first
if not self.device.is_on:
if not self.device.turn_on():
raise HomeAssistantError("An error occurred while turning on.")

success = self.device.manual_mode()
if not success:
raise HomeAssistantError("An error occurred while manual mode.")
success = self.device.change_fan_speed(
math.ceil(
percentage_to_ranged_value(
SPEED_RANGE[SKU_TO_BASE_DEVICE[self.device.device_type]], percentage
)
)
)
if not success:
# Switch to manual mode if not already set
if self.device.mode != VS_FAN_MODE_MANUAL:
if not self.device.manual_mode():
raise HomeAssistantError("An error occurred while setting manual mode.")

# Calculate the speed level and set it
speed_level = math.ceil(percentage_to_ranged_value(speed_range, percentage))
if not self.device.change_fan_speed(speed_level):
raise HomeAssistantError("An error occurred while changing fan speed.")

self.schedule_update_ha_state()

def set_preset_mode(self, preset_mode: str) -> None:
Expand Down
9 changes: 2 additions & 7 deletions homeassistant/components/wmspro/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from __future__ import annotations

import asyncio
from datetime import timedelta
from typing import Any

from wmspro.const import (
WMS_WebControl_pro_API_actionDescription,
WMS_WebControl_pro_API_actionType,
WMS_WebControl_pro_API_responseType,
)

from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
Expand All @@ -18,7 +18,6 @@
from . import WebControlProConfigEntry
from .entity import WebControlProGenericEntity

ACTION_DELAY = 0.5
SCAN_INTERVAL = timedelta(seconds=10)
PARALLEL_UPDATES = 1

Expand Down Expand Up @@ -61,7 +60,6 @@ async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
action = self._dest.action(self._drive_action_desc)
await action(percentage=100 - kwargs[ATTR_POSITION])
await asyncio.sleep(ACTION_DELAY)

@property
def is_closed(self) -> bool | None:
Expand All @@ -72,22 +70,19 @@ async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
action = self._dest.action(self._drive_action_desc)
await action(percentage=0)
await asyncio.sleep(ACTION_DELAY)

async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
action = self._dest.action(self._drive_action_desc)
await action(percentage=100)
await asyncio.sleep(ACTION_DELAY)

async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the device if in motion."""
action = self._dest.action(
WMS_WebControl_pro_API_actionDescription.ManualCommand,
WMS_WebControl_pro_API_actionType.Stop,
)
await action()
await asyncio.sleep(ACTION_DELAY)
await action(responseType=WMS_WebControl_pro_API_responseType.Detailed)


class WebControlProAwning(WebControlProCover):
Expand Down
21 changes: 12 additions & 9 deletions homeassistant/components/wmspro/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from __future__ import annotations

import asyncio
from datetime import timedelta
from typing import Any

from wmspro.const import WMS_WebControl_pro_API_actionDescription
from wmspro.const import (
WMS_WebControl_pro_API_actionDescription,
WMS_WebControl_pro_API_responseType,
)

from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
from homeassistant.core import HomeAssistant
Expand All @@ -17,7 +19,6 @@
from .const import BRIGHTNESS_SCALE
from .entity import WebControlProGenericEntity

ACTION_DELAY = 0.5
SCAN_INTERVAL = timedelta(seconds=15)
PARALLEL_UPDATES = 1

Expand Down Expand Up @@ -56,14 +57,16 @@ def is_on(self) -> bool:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.LightSwitch)
await action(onOffState=True)
await asyncio.sleep(ACTION_DELAY)
await action(
onOffState=True, responseType=WMS_WebControl_pro_API_responseType.Detailed
)

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.LightSwitch)
await action(onOffState=False)
await asyncio.sleep(ACTION_DELAY)
await action(
onOffState=False, responseType=WMS_WebControl_pro_API_responseType.Detailed
)


class WebControlProDimmer(WebControlProLight):
Expand All @@ -90,6 +93,6 @@ async def async_turn_on(self, **kwargs: Any) -> None:
WMS_WebControl_pro_API_actionDescription.LightDimming
)
await action(
percentage=brightness_to_value(BRIGHTNESS_SCALE, kwargs[ATTR_BRIGHTNESS])
percentage=brightness_to_value(BRIGHTNESS_SCALE, kwargs[ATTR_BRIGHTNESS]),
responseType=WMS_WebControl_pro_API_responseType.Detailed,
)
await asyncio.sleep(ACTION_DELAY)
2 changes: 1 addition & 1 deletion homeassistant/components/wmspro/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"documentation": "https://www.home-assistant.io/integrations/wmspro",
"integration_type": "hub",
"iot_class": "local_polling",
"requirements": ["pywmspro==0.2.2"]
"requirements": ["pywmspro==0.3.0"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading