Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump hatasmota to 0.8.0 #105440

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/tasmota/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_push",
"loggers": ["hatasmota"],
"mqtt": ["tasmota/discovery/#"],
"requirements": ["HATasmota==0.7.3"]
"requirements": ["HATasmota==0.8.0"]
}
9 changes: 8 additions & 1 deletion homeassistant/components/tasmota/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -122,6 +125,8 @@ async def async_added_to_hass(self) -> None:
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."""
Expand All @@ -135,6 +140,8 @@ def async_mqtt_connected(self, _: bool) -> None:
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
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/components/tasmota/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
120 changes: 120 additions & 0 deletions tests/components/tasmota/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import ANY

from hatasmota.const import (
CONF_DEEP_SLEEP,
CONF_MAC,
CONF_OFFLINE,
CONF_ONLINE,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions tests/components/tasmota/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions tests/components/tasmota/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions tests/components/tasmota/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down