Bump hatasmota to 0.0.29 (#43013)
This commit is contained in:
parent
621a0a5dd2
commit
8cc7069323
7 changed files with 266 additions and 13 deletions
|
@ -1,8 +1,10 @@
|
|||
"""The tests for the Tasmota sensor platform."""
|
||||
import copy
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
import hatasmota
|
||||
from hatasmota.utils import (
|
||||
get_topic_stat_status,
|
||||
get_topic_tele_sensor,
|
||||
|
@ -29,7 +31,7 @@ from .test_common import (
|
|||
help_test_entity_id_update_subscriptions,
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
||||
|
||||
DEFAULT_SENSOR_CONFIG = {
|
||||
|
@ -259,6 +261,7 @@ async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
async_fire_mqtt_message(
|
||||
hass, "tasmota_49A3BC/tele/STATE", '{"Wifi":{"Signal":20.5}}'
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "20.5"
|
||||
|
||||
|
@ -268,10 +271,142 @@ async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
"tasmota_49A3BC/stat/STATUS11",
|
||||
'{"StatusSTS":{"Wifi":{"Signal":20.0}}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "20.0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test state update via MQTT."""
|
||||
entity_reg = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
# Pre-enable the status sensor
|
||||
entity_reg.async_get_or_create(
|
||||
sensor.DOMAIN,
|
||||
"tasmota",
|
||||
"00000049A3BC_status_sensor_status_sensor_status_restart_reason",
|
||||
suggested_object_id="tasmota_status",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
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_status")
|
||||
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_status")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
# Test polled state update
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/stat/STATUS1",
|
||||
'{"StatusPRM":{"RestartReason":"Some reason"}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "Some reason"
|
||||
|
||||
# Test polled state update is ignored
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/stat/STATUS1",
|
||||
'{"StatusPRM":{"RestartReason":"Another reason"}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "Some reason"
|
||||
|
||||
# Device signals online again
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "Some reason"
|
||||
|
||||
# Test polled state update
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/stat/STATUS1",
|
||||
'{"StatusPRM":{"RestartReason":"Another reason"}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "Another reason"
|
||||
|
||||
# Test polled state update is ignored
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/stat/STATUS1",
|
||||
'{"StatusPRM":{"RestartReason":"Third reason"}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "Another reason"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
@patch.object(hatasmota.status_sensor, "datetime", Mock(wraps=datetime.datetime))
|
||||
async def test_restart_time_status_sensor_state_via_mqtt(
|
||||
hass, mqtt_mock, setup_tasmota
|
||||
):
|
||||
"""Test state update via MQTT."""
|
||||
entity_reg = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
# Pre-enable the status sensor
|
||||
entity_reg.async_get_or_create(
|
||||
sensor.DOMAIN,
|
||||
"tasmota",
|
||||
"00000049A3BC_status_sensor_status_sensor_last_restart_time",
|
||||
suggested_object_id="tasmota_status",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
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_status")
|
||||
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_status")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
# Test polled state update
|
||||
utc_now = datetime.datetime(2020, 11, 11, 8, 0, 0, tzinfo=dt.UTC)
|
||||
hatasmota.status_sensor.datetime.now.return_value = utc_now
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"tasmota_49A3BC/stat/STATUS11",
|
||||
'{"StatusSTS":{"UptimeSec":"3600"}}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.tasmota_status")
|
||||
assert state.state == "2020-11-11T07:00:00+00:00"
|
||||
|
||||
|
||||
async def test_attributes(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test correct attributes for sensors."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -301,7 +436,7 @@ async def test_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("device_class") == "temperature"
|
||||
assert state.attributes.get("friendly_name") == "Tasmota DHT11 Temperature"
|
||||
assert state.attributes.get("icon") is None
|
||||
assert state.attributes.get("unit_of_measurement") == "C"
|
||||
assert state.attributes.get("unit_of_measurement") == "°C"
|
||||
|
||||
state = hass.states.get("sensor.tasmota_beer_CarbonDioxide")
|
||||
assert state.attributes.get("device_class") is None
|
||||
|
@ -371,7 +506,7 @@ async def test_indexed_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("device_class") == "temperature"
|
||||
assert state.attributes.get("friendly_name") == "Tasmota Dummy1 Temperature 0"
|
||||
assert state.attributes.get("icon") is None
|
||||
assert state.attributes.get("unit_of_measurement") == "C"
|
||||
assert state.attributes.get("unit_of_measurement") == "°C"
|
||||
|
||||
state = hass.states.get("sensor.tasmota_dummy2_carbondioxide_1")
|
||||
assert state.attributes.get("device_class") is None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue