diff --git a/homeassistant/components/upcloud/__init__.py b/homeassistant/components/upcloud/__init__.py index c77b0fe3cdd..cd2cf5d02c0 100644 --- a/homeassistant/components/upcloud/__init__.py +++ b/homeassistant/components/upcloud/__init__.py @@ -18,6 +18,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send from homeassistant.helpers.entity import Entity from homeassistant.helpers.event import track_time_interval +from homeassistant.util import dt _LOGGER = logging.getLogger(__name__) @@ -82,6 +83,7 @@ def setup(hass, config): dispatcher_send(hass, SIGNAL_UPDATE_UPCLOUD) # Call the UpCloud API to refresh data + upcloud_update(dt.utcnow()) track_time_interval(hass, upcloud_update, scan_interval) return True @@ -108,6 +110,7 @@ class UpCloudServerEntity(Entity): self._upcloud = upcloud self.uuid = uuid self.data = None + self._unsub_handlers = [] @property def unique_id(self) -> str: @@ -124,10 +127,18 @@ class UpCloudServerEntity(Entity): async def async_added_to_hass(self): """Register callbacks.""" - async_dispatcher_connect( - self.hass, SIGNAL_UPDATE_UPCLOUD, self._update_callback + self._unsub_handlers.append( + async_dispatcher_connect( + self.hass, SIGNAL_UPDATE_UPCLOUD, self._update_callback + ) ) + async def async_will_remove_from_hass(self) -> None: + """Invoke unsubscription handlers.""" + for unsub in self._unsub_handlers: + unsub() + self._unsub_handlers.clear() + @callback def _update_callback(self): """Call update method.""" diff --git a/homeassistant/components/upcloud/manifest.json b/homeassistant/components/upcloud/manifest.json index 62ce608a911..0499ce1e9ad 100644 --- a/homeassistant/components/upcloud/manifest.json +++ b/homeassistant/components/upcloud/manifest.json @@ -1,9 +1,9 @@ { "domain": "upcloud", - "name": "Upcloud", + "name": "UpCloud", "documentation": "https://www.home-assistant.io/integrations/upcloud", "requirements": [ - "upcloud-api==0.4.3" + "upcloud-api==0.4.5" ], "dependencies": [], "codeowners": [ diff --git a/homeassistant/components/upcloud/switch.py b/homeassistant/components/upcloud/switch.py index 66f3d9f42b1..5cb1d86671e 100644 --- a/homeassistant/components/upcloud/switch.py +++ b/homeassistant/components/upcloud/switch.py @@ -6,8 +6,9 @@ import voluptuous as vol from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice from homeassistant.const import STATE_OFF import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import dispatcher_send -from . import CONF_SERVERS, DATA_UPCLOUD, UpCloudServerEntity +from . import CONF_SERVERS, DATA_UPCLOUD, SIGNAL_UPDATE_UPCLOUD, UpCloudServerEntity _LOGGER = logging.getLogger(__name__) @@ -34,6 +35,7 @@ class UpCloudSwitch(UpCloudServerEntity, SwitchDevice): """Start the server.""" if self.state == STATE_OFF: self.data.start() + dispatcher_send(self.hass, SIGNAL_UPDATE_UPCLOUD) def turn_off(self, **kwargs): """Stop the server.""" diff --git a/requirements_all.txt b/requirements_all.txt index 987b231005d..c2eabe3a060 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1959,7 +1959,7 @@ twilio==6.32.0 unifiled==0.11 # homeassistant.components.upcloud -upcloud-api==0.4.3 +upcloud-api==0.4.5 # homeassistant.components.huawei_lte url-normalize==1.4.1