Skip to content

Commit

Permalink
Ensure group state is recalculated when re-adding on reload (#40497)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 23, 2020
1 parent 6c8e0e2 commit 3880ac0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/group/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
STATE_OPEN,
STATE_OPENING,
)
from homeassistant.core import State
from homeassistant.core import CoreState, State
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_state_change_event

Expand Down Expand Up @@ -162,6 +162,10 @@ async def async_added_to_hass(self):
self.hass, self._entities, self._update_supported_features_event
)
)

if self.hass.state == CoreState.running:
await self.async_update()
return
await super().async_added_to_hass()

@property
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/group/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import State
from homeassistant.core import CoreState, State
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
Expand Down Expand Up @@ -111,6 +111,11 @@ async def async_state_changed_listener(event):
self.hass, self._entity_ids, async_state_changed_listener
)
)

if self.hass.state == CoreState.running:
await self.async_update()
return

await super().async_added_to_hass()

@property
Expand Down
7 changes: 7 additions & 0 deletions tests/components/group/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ async def test_reload_with_base_integration_platform_not_setup(hass):
},
)
await hass.async_block_till_done()
hass.states.async_set("light.master_hall_lights", STATE_ON)
hass.states.async_set("light.master_hall_lights_2", STATE_OFF)

hass.states.async_set("light.outside_patio_lights", STATE_OFF)
hass.states.async_set("light.outside_patio_lights_2", STATE_OFF)

yaml_path = path.join(
_get_fixtures_base_path(),
Expand All @@ -755,6 +760,8 @@ async def test_reload_with_base_integration_platform_not_setup(hass):
assert hass.states.get("light.light_group") is None
assert hass.states.get("light.master_hall_lights_g") is not None
assert hass.states.get("light.outside_patio_lights_g") is not None
assert hass.states.get("light.master_hall_lights_g").state == STATE_ON
assert hass.states.get("light.outside_patio_lights_g").state == STATE_OFF


def _get_fixtures_base_path():
Expand Down

0 comments on commit 3880ac0

Please sign in to comment.