Bump hatasmota to 0.8.0 (#105440)
* Bump hatasmota to 0.8.0 * Keep devices with deep sleep support always available * Add tests
This commit is contained in:
parent
4752d37df7
commit
b5af987a18
11 changed files with 313 additions and 4 deletions
|
@ -8,5 +8,5 @@
|
|||
"iot_class": "local_push",
|
||||
"loggers": ["hatasmota"],
|
||||
"mqtt": ["tasmota/discovery/#"],
|
||||
"requirements": ["HATasmota==0.7.3"]
|
||||
"requirements": ["HATasmota==0.8.0"]
|
||||
}
|
||||
|
|
|
@ -112,8 +112,11 @@ class TasmotaAvailability(TasmotaEntity):
|
|||
|
||||
def __init__(self, **kwds: Any) -> None:
|
||||
"""Initialize the availability mixin."""
|
||||
self._available = False
|
||||
super().__init__(**kwds)
|
||||
if self._tasmota_entity.deep_sleep_enabled:
|
||||
self._available = True
|
||||
else:
|
||||
self._available = False
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Subscribe to MQTT events."""
|
||||
|
@ -122,6 +125,8 @@ class TasmotaAvailability(TasmotaEntity):
|
|||
async_subscribe_connection_status(self.hass, self.async_mqtt_connected)
|
||||
)
|
||||
await super().async_added_to_hass()
|
||||
if self._tasmota_entity.deep_sleep_enabled:
|
||||
await self._tasmota_entity.poll_status()
|
||||
|
||||
async def availability_updated(self, available: bool) -> None:
|
||||
"""Handle updated availability."""
|
||||
|
@ -135,6 +140,8 @@ class TasmotaAvailability(TasmotaEntity):
|
|||
if not self.hass.is_stopping:
|
||||
if not mqtt_connected(self.hass):
|
||||
self._available = False
|
||||
elif self._tasmota_entity.deep_sleep_enabled:
|
||||
self._available = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
|
|
|
@ -28,7 +28,7 @@ DoorBirdPy==2.1.0
|
|||
HAP-python==4.9.1
|
||||
|
||||
# homeassistant.components.tasmota
|
||||
HATasmota==0.7.3
|
||||
HATasmota==0.8.0
|
||||
|
||||
# homeassistant.components.mastodon
|
||||
Mastodon.py==1.5.1
|
||||
|
|
|
@ -25,7 +25,7 @@ DoorBirdPy==2.1.0
|
|||
HAP-python==4.9.1
|
||||
|
||||
# homeassistant.components.tasmota
|
||||
HATasmota==0.7.3
|
||||
HATasmota==0.8.0
|
||||
|
||||
# homeassistant.components.doods
|
||||
# homeassistant.components.generic
|
||||
|
|
|
@ -31,6 +31,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -313,6 +315,21 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
config["swn"][0] = "Test"
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, Platform.BINARY_SENSOR, config
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -323,6 +340,18 @@ async def test_availability(
|
|||
await help_test_availability(hass, mqtt_mock, Platform.BINARY_SENSOR, config)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability when deep sleep is enabled."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
config["swn"][0] = "Test"
|
||||
await help_test_deep_sleep_availability(
|
||||
hass, mqtt_mock, Platform.BINARY_SENSOR, config
|
||||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
|
@ -4,6 +4,7 @@ import json
|
|||
from unittest.mock import ANY
|
||||
|
||||
from hatasmota.const import (
|
||||
CONF_DEEP_SLEEP,
|
||||
CONF_MAC,
|
||||
CONF_OFFLINE,
|
||||
CONF_ONLINE,
|
||||
|
@ -188,6 +189,76 @@ async def help_test_availability_when_connection_lost(
|
|||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass,
|
||||
mqtt_client_mock,
|
||||
mqtt_mock,
|
||||
domain,
|
||||
config,
|
||||
sensor_config=None,
|
||||
object_id="tasmota_test",
|
||||
):
|
||||
"""Test availability after MQTT disconnection when deep sleep is enabled.
|
||||
|
||||
This is a test helper for the TasmotaAvailability mixin.
|
||||
"""
|
||||
config[CONF_DEEP_SLEEP] = 1
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
if sensor_config:
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/sensors",
|
||||
json.dumps(sensor_config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Device online
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Disconnected from MQTT server -> state changed to unavailable
|
||||
mqtt_mock.connected = False
|
||||
await hass.async_add_executor_job(mqtt_client_mock.on_disconnect, None, None, 0)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
# Reconnected to MQTT server -> state no longer unavailable
|
||||
mqtt_mock.connected = True
|
||||
await hass.async_add_executor_job(mqtt_client_mock.on_connect, None, None, None, 0)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Receive LWT again
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
get_topic_tele_will(config),
|
||||
config_get_state_online(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
get_topic_tele_will(config),
|
||||
config_get_state_offline(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def help_test_availability(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
|
@ -236,6 +307,55 @@ async def help_test_availability(
|
|||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def help_test_deep_sleep_availability(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
domain,
|
||||
config,
|
||||
sensor_config=None,
|
||||
object_id="tasmota_test",
|
||||
):
|
||||
"""Test availability when deep sleep is enabled.
|
||||
|
||||
This is a test helper for the TasmotaAvailability mixin.
|
||||
"""
|
||||
config[CONF_DEEP_SLEEP] = 1
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
if sensor_config:
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/sensors",
|
||||
json.dumps(sensor_config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
get_topic_tele_will(config),
|
||||
config_get_state_online(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
get_topic_tele_will(config),
|
||||
config_get_state_offline(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(f"{domain}.{object_id}")
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def help_test_availability_discovery_update(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
|
|
|
@ -22,6 +22,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -663,6 +665,27 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
config["rl"][0] = 3
|
||||
config["rl"][1] = 3
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass,
|
||||
mqtt_client_mock,
|
||||
mqtt_mock,
|
||||
Platform.COVER,
|
||||
config,
|
||||
object_id="test_cover_1",
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -676,6 +699,19 @@ async def test_availability(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
config["rl"][0] = 3
|
||||
config["rl"][1] = 3
|
||||
await help_test_deep_sleep_availability(
|
||||
hass, mqtt_mock, Platform.COVER, config, object_id="test_cover_1"
|
||||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
|
@ -22,6 +22,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -232,6 +234,20 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, Platform.FAN, config, object_id="tasmota"
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -243,6 +259,17 @@ async def test_availability(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
await help_test_deep_sleep_availability(
|
||||
hass, mqtt_mock, Platform.FAN, config, object_id="tasmota"
|
||||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
|
@ -22,6 +22,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -1669,6 +1671,21 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
config["lt_st"] = 1 # 1 channel light (Dimmer)
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, Platform.LIGHT, config
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -1679,6 +1696,16 @@ async def test_availability(
|
|||
await help_test_availability(hass, mqtt_mock, Platform.LIGHT, config)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
config["lt_st"] = 1 # 1 channel light (Dimmer)
|
||||
await help_test_deep_sleep_availability(hass, mqtt_mock, Platform.LIGHT, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
|
@ -28,6 +28,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -1222,6 +1224,26 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass,
|
||||
mqtt_client_mock,
|
||||
mqtt_mock,
|
||||
Platform.SENSOR,
|
||||
config,
|
||||
sensor_config,
|
||||
"tasmota_dht11_temperature",
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -1238,6 +1260,22 @@ async def test_availability(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
await help_test_deep_sleep_availability(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
Platform.SENSOR,
|
||||
config,
|
||||
sensor_config,
|
||||
"tasmota_dht11_temperature",
|
||||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
|
@ -20,6 +20,8 @@ from .test_common import (
|
|||
help_test_availability_discovery_update,
|
||||
help_test_availability_poll_state,
|
||||
help_test_availability_when_connection_lost,
|
||||
help_test_deep_sleep_availability,
|
||||
help_test_deep_sleep_availability_when_connection_lost,
|
||||
help_test_discovery_device_remove,
|
||||
help_test_discovery_removal,
|
||||
help_test_discovery_update_unchanged,
|
||||
|
@ -158,6 +160,20 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
await help_test_deep_sleep_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, Platform.SWITCH, config
|
||||
)
|
||||
|
||||
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
@ -167,6 +183,15 @@ async def test_availability(
|
|||
await help_test_availability(hass, mqtt_mock, Platform.SWITCH, config)
|
||||
|
||||
|
||||
async def test_deep_sleep_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
await help_test_deep_sleep_availability(hass, mqtt_mock, Platform.SWITCH, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue