Add additional tasmota tests (#98695)

This commit is contained in:
Erik Montnemery 2023-08-20 14:02:53 +02:00 committed by GitHub
parent 614904512c
commit f07724ff52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View file

@ -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),

View file

@ -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