From 5c28a11911c91c947094f9b5925e632de44bb7d9 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Thu, 6 Jun 2024 19:06:51 +0200 Subject: [PATCH] Update to HA 2024.6 --- requirements_dev.txt | 2 +- requirements_test.txt | 2 +- requirements_test312.txt | 2 +- scripts/pytest_all_ha_versions_python312 | 11 +- scripts/setup | 2 + tests/coordinator/test_coordinator_keep_on.py | 103 +++++++++++++++++- 6 files changed, 116 insertions(+), 6 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 052ded7..d16b11c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1 +1 @@ -homeassistant==2024.4.3 +homeassistant==2024.6.0 diff --git a/requirements_test.txt b/requirements_test.txt index 6a6c4e9..54801f7 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1 +1 @@ -pytest-homeassistant-custom-component==0.13.114 +pytest-homeassistant-custom-component==0.13.132 diff --git a/requirements_test312.txt b/requirements_test312.txt index 6a6c4e9..54801f7 100644 --- a/requirements_test312.txt +++ b/requirements_test312.txt @@ -1 +1 @@ -pytest-homeassistant-custom-component==0.13.114 +pytest-homeassistant-custom-component==0.13.132 diff --git a/scripts/pytest_all_ha_versions_python312 b/scripts/pytest_all_ha_versions_python312 index 3ebcf4f..78a91f3 100644 --- a/scripts/pytest_all_ha_versions_python312 +++ b/scripts/pytest_all_ha_versions_python312 @@ -39,5 +39,14 @@ pip3 install -qq homeassistant==2024.3.3 pytest-homeassistant-custom-component== run_next_test "auto" # As of HA 2024.4, Python 3.11 is not supported. -pip3 install -qq homeassistant==2024.4.3 pytest-homeassistant-custom-component==0.13.114 + +#pip3 install -qq homeassistant==2024.4.4 pytest-homeassistant-custom-component==0.13.115 +#run_next_test "auto" +# Depends on non-existng version of mypy-dev + +#pip3 install -qq homeassistant==2024.5.5 pytest-homeassistant-custom-component==0.13.125 +#run_next_test "auto" +# Depends on non-existng version of mypy-dev + +pip3 install -qq homeassistant==2024.6.0 pytest-homeassistant-custom-component==0.13.132 run_next_test "auto" diff --git a/scripts/setup b/scripts/setup index 6251382..569f625 100755 --- a/scripts/setup +++ b/scripts/setup @@ -2,6 +2,8 @@ set -e +sudo chown -R vscode:vscode /workspaces + cd "$(dirname "$0")/.." python3 -m pip install --requirement requirements_dev.txt diff --git a/tests/coordinator/test_coordinator_keep_on.py b/tests/coordinator/test_coordinator_keep_on.py index e7a8dd6..36aa5d0 100644 --- a/tests/coordinator/test_coordinator_keep_on.py +++ b/tests/coordinator/test_coordinator_keep_on.py @@ -454,7 +454,56 @@ async def test_coordinator_keep_on4( assert coordinator.auto_charging_state == STATE_ON assert coordinator.sensor.state == STATE_ON - # Move back time to recreate the schedule + # Unsubscribe to listeners + coordinator.unsubscribe_listeners() + + +async def test_coordinator_keep_on4b( + hass: HomeAssistant, skip_service_calls, set_cet_timezone, freezer +): + """Test Coordinator.""" + + freezer.move_to("2022-09-30T14:00:00+02:00") + + entity_registry: EntityRegistry = async_entity_registry_get(hass) + MockSOCEntity.create(hass, entity_registry, "40") + MockTargetSOCEntity.create(hass, entity_registry, "80") + MockPriceEntity.create(hass, entity_registry, 123) + MockChargerEntity.create(hass, entity_registry, STATE_OFF) + + # Test with max price 0.0 and 6.0 PCT/h. + # This should give 7h charging, 02-09, or 23-00 + 03-09 + # Test "if self.ev_soc >= self.ev_target_soc:" + + config_entry = MockConfigEntry( + domain=DOMAIN, data=MOCK_CONFIG_KEEP_ON1, entry_id="test" + ) + config_entry.add_to_hass(hass) + coordinator = EVSmartChargingCoordinator(hass, config_entry) + assert coordinator is not None + + sensor: EVSmartChargingSensorCharging = EVSmartChargingSensorCharging(config_entry) + assert sensor is not None + await coordinator.add_sensor([sensor]) + + # Provide price + MockPriceEntity.set_state(hass, PRICE_20220930, PRICE_20221001) + await coordinator.update_sensors() + await hass.async_block_till_done() + assert coordinator.tomorrow_valid + + # Turn on switches + await coordinator.switch_active_update(True) + await coordinator.switch_apply_limit_update(False) + await coordinator.switch_continuous_update(True) + await coordinator.switch_ev_connected_update(True) + await coordinator.switch_keep_on_update(False) + await hass.async_block_till_done() + + assert coordinator.auto_charging_state == STATE_OFF + assert coordinator.sensor.state == STATE_OFF + + # Move time and turn on keep on freezer.move_to("2022-09-30T20:00:00+02:00") MockPriceEntity.set_state(hass, PRICE_20220930, PRICE_20221001) MockSOCEntity.set_state(hass, "40") @@ -722,7 +771,57 @@ async def test_coordinator_keep_on6( assert coordinator.auto_charging_state == STATE_ON assert coordinator.sensor.state == STATE_ON - # Move back time to recreate the schedule + # Unsubscribe to listeners + coordinator.unsubscribe_listeners() + + +async def test_coordinator_keep_on6b( + hass: HomeAssistant, skip_service_calls, set_cet_timezone, freezer +): + """Test Coordinator.""" + + freezer.move_to("2022-09-30T14:00:00+02:00") + + entity_registry: EntityRegistry = async_entity_registry_get(hass) + MockSOCEntity.create(hass, entity_registry, "40") + MockTargetSOCEntity.create(hass, entity_registry, "80") + MockPriceEntity.create(hass, entity_registry, 123) + MockChargerEntity.create(hass, entity_registry, STATE_OFF) + + # Test with max price 0.0 and 6.0 PCT/h. + # For the case with non-continuous charging + # This should give 7h charging, 02-09, or 23-00 + 03-09 + # Test "if self.ev_soc >= self.ev_target_soc:" + + config_entry = MockConfigEntry( + domain=DOMAIN, data=MOCK_CONFIG_KEEP_ON1, entry_id="test" + ) + config_entry.add_to_hass(hass) + coordinator = EVSmartChargingCoordinator(hass, config_entry) + assert coordinator is not None + + sensor: EVSmartChargingSensorCharging = EVSmartChargingSensorCharging(config_entry) + assert sensor is not None + await coordinator.add_sensor([sensor]) + + # Provide price + MockPriceEntity.set_state(hass, PRICE_20220930, PRICE_20221001) + await coordinator.update_sensors() + await hass.async_block_till_done() + assert coordinator.tomorrow_valid + + # Turn on switches + await coordinator.switch_active_update(True) + await coordinator.switch_apply_limit_update(False) + await coordinator.switch_continuous_update(False) + await coordinator.switch_ev_connected_update(True) + await coordinator.switch_keep_on_update(True) + await hass.async_block_till_done() + + assert coordinator.auto_charging_state == STATE_OFF + assert coordinator.sensor.state == STATE_OFF + + # Move time freezer.move_to("2022-09-30T20:00:00+02:00") MockPriceEntity.set_state(hass, PRICE_20220930, PRICE_20221001) MockSOCEntity.set_state(hass, "40")