diff --git a/tests/components/tasmota/test_cover.py b/tests/components/tasmota/test_cover.py index 5c1364f1f77..e2bdc8b2ca7 100644 --- a/tests/components/tasmota/test_cover.py +++ b/tests/components/tasmota/test_cover.py @@ -55,6 +55,7 @@ async def test_missing_relay( @pytest.mark.parametrize( ("relay_config", "num_covers"), [ + ([3, 3, 3, 3, 3, 3, 1, 1, 3, 3] + [3, 3] * 12, 16), ([3, 3, 3, 3, 3, 3, 1, 1, 3, 3], 4), ([3, 3, 3, 3, 0, 0, 0, 0], 2), ([3, 3, 1, 1, 0, 0, 0, 0], 1), diff --git a/tests/components/tasmota/test_sensor.py b/tests/components/tasmota/test_sensor.py index 22ee652aef3..4e79b8ad0d5 100644 --- a/tests/components/tasmota/test_sensor.py +++ b/tests/components/tasmota/test_sensor.py @@ -585,6 +585,48 @@ async def test_status_sensor_state_via_mqtt( assert not entity.force_update +@pytest.mark.parametrize("status_sensor_disabled", [False]) +async def test_battery_sensor_state_via_mqtt( + hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota +) -> None: + """Test state update via MQTT.""" + config = copy.deepcopy(DEFAULT_CONFIG) + config["bat"] = 1 # BatteryPercentage feature enabled + mac = config["mac"] + + async_fire_mqtt_message( + hass, + f"{DEFAULT_PREFIX}/{mac}/config", + json.dumps(config), + ) + await hass.async_block_till_done() + await hass.async_block_till_done() + + state = hass.states.get("sensor.tasmota_battery_level") + assert state.state == "unavailable" + assert not state.attributes.get(ATTR_ASSUMED_STATE) + + async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online") + await hass.async_block_till_done() + state = hass.states.get("sensor.tasmota_battery_level") + assert state.state == STATE_UNKNOWN + assert not state.attributes.get(ATTR_ASSUMED_STATE) + + # Test pushed state update + async_fire_mqtt_message( + hass, "tasmota_49A3BC/tele/STATE", '{"BatteryPercentage":55}' + ) + await hass.async_block_till_done() + state = hass.states.get("sensor.tasmota_battery_level") + assert state.state == "55" + assert state.attributes == { + "device_class": "battery", + "friendly_name": "Tasmota Battery Level", + "state_class": "measurement", + "unit_of_measurement": "%", + } + + @pytest.mark.parametrize("status_sensor_disabled", [False]) async def test_single_shot_status_sensor_state_via_mqtt( hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota