From e57634b1e02ddb981ad4c92f78ae336b960f7f0e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 9 May 2021 21:57:27 +0200 Subject: [PATCH] Bump hatasmota to 0.2.12 (#50372) --- .../components/tasmota/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/tasmota/test_sensor.py | 120 ++++++++++++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tasmota/manifest.json b/homeassistant/components/tasmota/manifest.json index b3a4bb09fea..a6e7a1d45a8 100644 --- a/homeassistant/components/tasmota/manifest.json +++ b/homeassistant/components/tasmota/manifest.json @@ -3,7 +3,7 @@ "name": "Tasmota", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tasmota", - "requirements": ["hatasmota==0.2.11"], + "requirements": ["hatasmota==0.2.12"], "dependencies": ["mqtt"], "mqtt": ["tasmota/discovery/#"], "codeowners": ["@emontnemery"], diff --git a/requirements_all.txt b/requirements_all.txt index 6a9d9ca91ed..2fcec0aa9c5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -735,7 +735,7 @@ hass-nabucasa==0.43.0 hass_splunk==0.1.1 # homeassistant.components.tasmota -hatasmota==0.2.11 +hatasmota==0.2.12 # homeassistant.components.jewish_calendar hdate==0.10.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3b34a983f5e..b323cb3fed0 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -405,7 +405,7 @@ hangups==0.4.11 hass-nabucasa==0.43.0 # homeassistant.components.tasmota -hatasmota==0.2.11 +hatasmota==0.2.12 # homeassistant.components.jewish_calendar hdate==0.10.2 diff --git a/tests/components/tasmota/test_sensor.py b/tests/components/tasmota/test_sensor.py index 0d6820f2d34..425fa3f26f6 100644 --- a/tests/components/tasmota/test_sensor.py +++ b/tests/components/tasmota/test_sensor.py @@ -43,6 +43,15 @@ DEFAULT_SENSOR_CONFIG = { } } +BAD_INDEXED_SENSOR_CONFIG_3 = { + "sn": { + "Time": "2020-09-25T12:47:15", + "ENERGY": { + "ApparentPower": [7.84, 1.23, 2.34], + }, + } +} + INDEXED_SENSOR_CONFIG = { "sn": { "Time": "2020-09-25T12:47:15", @@ -224,6 +233,117 @@ async def test_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota): assert state.state == "7.8" +async def test_bad_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota): + """Test state update via MQTT where sensor is not matching configuration.""" + config = copy.deepcopy(DEFAULT_CONFIG) + sensor_config = copy.deepcopy(BAD_INDEXED_SENSOR_CONFIG_3) + mac = config["mac"] + + async_fire_mqtt_message( + hass, + f"{DEFAULT_PREFIX}/{mac}/config", + json.dumps(config), + ) + await hass.async_block_till_done() + async_fire_mqtt_message( + hass, + f"{DEFAULT_PREFIX}/{mac}/sensors", + json.dumps(sensor_config), + ) + await hass.async_block_till_done() + + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "unavailable" + assert not state.attributes.get(ATTR_ASSUMED_STATE) + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == "unavailable" + assert not state.attributes.get(ATTR_ASSUMED_STATE) + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == "unavailable" + assert not state.attributes.get(ATTR_ASSUMED_STATE) + + async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online") + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == STATE_UNKNOWN + assert not state.attributes.get(ATTR_ASSUMED_STATE) + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == STATE_UNKNOWN + assert not state.attributes.get(ATTR_ASSUMED_STATE) + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == STATE_UNKNOWN + assert not state.attributes.get(ATTR_ASSUMED_STATE) + + # Test periodic state update + async_fire_mqtt_message( + hass, "tasmota_49A3BC/tele/SENSOR", '{"ENERGY":{"ApparentPower":[1.2,3.4,5.6]}}' + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "1.2" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == "3.4" + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == "5.6" + + # Test periodic state update with too few values + async_fire_mqtt_message( + hass, "tasmota_49A3BC/tele/SENSOR", '{"ENERGY":{"ApparentPower":[7.8,9.0]}}' + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "7.8" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == "9.0" + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == STATE_UNKNOWN + + async_fire_mqtt_message( + hass, "tasmota_49A3BC/tele/SENSOR", '{"ENERGY":{"ApparentPower":2.3}}' + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "2.3" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == STATE_UNKNOWN + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == STATE_UNKNOWN + + # Test polled state update + async_fire_mqtt_message( + hass, + "tasmota_49A3BC/stat/STATUS10", + '{"StatusSNS":{"ENERGY":{"ApparentPower":[1.2,3.4,5.6]}}}', + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "1.2" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == "3.4" + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == "5.6" + + # Test polled state update with too few values + async_fire_mqtt_message( + hass, + "tasmota_49A3BC/stat/STATUS10", + '{"StatusSNS":{"ENERGY":{"ApparentPower":[7.8,9.0]}}}', + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "7.8" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == "9.0" + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == STATE_UNKNOWN + + async_fire_mqtt_message( + hass, + "tasmota_49A3BC/stat/STATUS10", + '{"StatusSNS":{"ENERGY":{"ApparentPower":2.3}}}', + ) + state = hass.states.get("sensor.tasmota_energy_apparentpower_0") + assert state.state == "2.3" + state = hass.states.get("sensor.tasmota_energy_apparentpower_1") + assert state.state == STATE_UNKNOWN + state = hass.states.get("sensor.tasmota_energy_apparentpower_2") + assert state.state == STATE_UNKNOWN + + @pytest.mark.parametrize("status_sensor_disabled", [False]) async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota): """Test state update via MQTT."""