Support reloading Tasmota config entries (#42097)
This commit is contained in:
parent
3661035397
commit
de35d58fd4
15 changed files with 179 additions and 75 deletions
|
@ -1,5 +1,6 @@
|
|||
"""The tests for the Tasmota sensor platform."""
|
||||
import copy
|
||||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
from hatasmota.utils import (
|
||||
|
@ -9,9 +10,11 @@ from hatasmota.utils import (
|
|||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import sensor
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNKNOWN
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .test_common import (
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -27,7 +30,7 @@ from .test_common import (
|
|||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
||||
|
||||
DEFAULT_SENSOR_CONFIG = {
|
||||
"sn": {
|
||||
|
@ -377,6 +380,64 @@ async def test_indexed_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("unit_of_measurement") == "ppm"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
async def test_enable_status_sensor(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test enabling status sensor."""
|
||||
entity_reg = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
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 is None
|
||||
entry = entity_reg.async_get("sensor.tasmota_status")
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by == "integration"
|
||||
|
||||
# Enable the status sensor
|
||||
updated_entry = entity_reg.async_update_entity(
|
||||
"sensor.tasmota_status", disabled_by=None
|
||||
)
|
||||
assert updated_entry != entry
|
||||
assert updated_entry.disabled is False
|
||||
await hass.async_block_till_done()
|
||||
|
||||
async_fire_time_changed(
|
||||
hass,
|
||||
dt.utcnow()
|
||||
+ timedelta(
|
||||
seconds=config_entries.EntityRegistryDisabledHandler.RELOAD_AFTER_UPDATE_DELAY
|
||||
+ 1
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Fake re-send of retained discovery message
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
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)
|
||||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue