Commit for rebase
This commit is contained in:
@@ -86,7 +86,7 @@ class CentralFeaturePowerManager(BaseFeatureManager):
|
||||
async_track_state_change_event(
|
||||
self.hass,
|
||||
[self._power_sensor_entity_id],
|
||||
self._async_power_sensor_changed,
|
||||
self._power_sensor_changed,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -94,12 +94,12 @@ class CentralFeaturePowerManager(BaseFeatureManager):
|
||||
async_track_state_change_event(
|
||||
self.hass,
|
||||
[self._max_power_sensor_entity_id],
|
||||
self._async_max_power_sensor_changed,
|
||||
self._max_power_sensor_changed,
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
async def _async_power_sensor_changed(self, event: Event[EventStateChangedData]):
|
||||
async def _power_sensor_changed(self, event: Event[EventStateChangedData]):
|
||||
"""Handle power changes."""
|
||||
_LOGGER.debug("Thermostat %s - Receive new Power event", self)
|
||||
_LOGGER.debug(event)
|
||||
@@ -125,9 +125,7 @@ class CentralFeaturePowerManager(BaseFeatureManager):
|
||||
_LOGGER.error("Unable to update current_power from sensor: %s", ex)
|
||||
|
||||
@callback
|
||||
async def _async_max_power_sensor_changed(
|
||||
self, event: Event[EventStateChangedData]
|
||||
):
|
||||
async def _max_power_sensor_changed(self, event: Event[EventStateChangedData]):
|
||||
"""Handle power max changes."""
|
||||
_LOGGER.debug("Thermostat %s - Receive new Power Max event", self.name)
|
||||
_LOGGER.debug(event)
|
||||
|
||||
@@ -429,3 +429,35 @@ async def test_central_power_manageer_calculate_shedding(
|
||||
|
||||
# Check registered calls
|
||||
assert registered_calls == expected_results
|
||||
|
||||
|
||||
async def test_central_power_manager_power_event(hass: HomeAssistant):
|
||||
"""Tests the Power sensor event"""
|
||||
vtherm_api: VersatileThermostatAPI = MagicMock(spec=VersatileThermostatAPI)
|
||||
central_power_manager = CentralFeaturePowerManager(hass, vtherm_api)
|
||||
|
||||
assert central_power_manager.current_power is None
|
||||
assert central_power_manager.power_temperature is None
|
||||
assert central_power_manager.name == "centralPowerManager"
|
||||
|
||||
# 2. post_init
|
||||
central_power_manager.post_init(
|
||||
{
|
||||
CONF_POWER_SENSOR: power_entity_id,
|
||||
CONF_MAX_POWER_SENSOR: max_power_entity_id,
|
||||
CONF_USE_POWER_FEATURE: use_power_feature,
|
||||
CONF_PRESET_POWER: 13,
|
||||
}
|
||||
)
|
||||
|
||||
assert central_power_manager.is_configured == True
|
||||
assert central_power_manager.current_max_power is None
|
||||
assert central_power_manager.current_power is None
|
||||
assert central_power_manager.power_temperature == 13
|
||||
|
||||
# 3. start listening
|
||||
central_power_manager.start_listening()
|
||||
assert len(central_power_manager._active_listener) == 2
|
||||
|
||||
tz = get_tz(hass) # pylint: disable=invalid-name
|
||||
now: datetime = datetime.now(tz=tz)
|
||||
|
||||
Reference in New Issue
Block a user