mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 19:57:52 +00:00
Bump hatasmota from 0.0.27 (#42802)
* Adjust tests * Add test for deprecated discovery message * Update status sensors * Bump hatasmota to 0.0.27 * Update tests
This commit is contained in:
parent
6e9b65405a
commit
51b4bc547c
@ -3,7 +3,7 @@
|
|||||||
"name": "Tasmota (beta)",
|
"name": "Tasmota (beta)",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tasmota",
|
"documentation": "https://www.home-assistant.io/integrations/tasmota",
|
||||||
"requirements": ["hatasmota==0.0.26"],
|
"requirements": ["hatasmota==0.0.27"],
|
||||||
"dependencies": ["mqtt"],
|
"dependencies": ["mqtt"],
|
||||||
"mqtt": ["tasmota/discovery/#"],
|
"mqtt": ["tasmota/discovery/#"],
|
||||||
"codeowners": ["@emontnemery"]
|
"codeowners": ["@emontnemery"]
|
||||||
|
@ -37,6 +37,7 @@ from hatasmota.const import (
|
|||||||
SENSOR_STATUS_IP,
|
SENSOR_STATUS_IP,
|
||||||
SENSOR_STATUS_LINK_COUNT,
|
SENSOR_STATUS_LINK_COUNT,
|
||||||
SENSOR_STATUS_MQTT_COUNT,
|
SENSOR_STATUS_MQTT_COUNT,
|
||||||
|
SENSOR_STATUS_RESTART,
|
||||||
SENSOR_STATUS_RSSI,
|
SENSOR_STATUS_RSSI,
|
||||||
SENSOR_STATUS_SIGNAL,
|
SENSOR_STATUS_SIGNAL,
|
||||||
SENSOR_STATUS_UPTIME,
|
SENSOR_STATUS_UPTIME,
|
||||||
@ -59,7 +60,6 @@ from homeassistant.const import (
|
|||||||
DEVICE_CLASS_PRESSURE,
|
DEVICE_CLASS_PRESSURE,
|
||||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
DEVICE_CLASS_TIMESTAMP,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
@ -108,14 +108,15 @@ SENSOR_DEVICE_CLASS_ICON_MAP = {
|
|||||||
SENSOR_PRESSUREATSEALEVEL: {DEVICE_CLASS: DEVICE_CLASS_PRESSURE},
|
SENSOR_PRESSUREATSEALEVEL: {DEVICE_CLASS: DEVICE_CLASS_PRESSURE},
|
||||||
SENSOR_PROXIMITY: {ICON: "mdi:ruler"},
|
SENSOR_PROXIMITY: {ICON: "mdi:ruler"},
|
||||||
SENSOR_REACTIVE_POWERUSAGE: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
SENSOR_REACTIVE_POWERUSAGE: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
||||||
|
SENSOR_STATUS_RESTART: {ICON: "mdi:information-outline"},
|
||||||
SENSOR_STATUS_SIGNAL: {DEVICE_CLASS: DEVICE_CLASS_SIGNAL_STRENGTH},
|
SENSOR_STATUS_SIGNAL: {DEVICE_CLASS: DEVICE_CLASS_SIGNAL_STRENGTH},
|
||||||
SENSOR_STATUS_RSSI: {ICON: "mdi:access-point"},
|
SENSOR_STATUS_RSSI: {ICON: "mdi:access-point"},
|
||||||
|
SENSOR_STATUS_UPTIME: {ICON: "mdi:progress-clock"},
|
||||||
SENSOR_TEMPERATURE: {DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE},
|
SENSOR_TEMPERATURE: {DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE},
|
||||||
SENSOR_TODAY: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
SENSOR_TODAY: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
||||||
SENSOR_TOTAL: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
SENSOR_TOTAL: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
||||||
SENSOR_TOTAL_START_TIME: {ICON: "mdi:progress-clock"},
|
SENSOR_TOTAL_START_TIME: {ICON: "mdi:progress-clock"},
|
||||||
SENSOR_TVOC: {ICON: "mdi:air-filter"},
|
SENSOR_TVOC: {ICON: "mdi:air-filter"},
|
||||||
SENSOR_STATUS_UPTIME: {DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP},
|
|
||||||
SENSOR_VOLTAGE: {ICON: "mdi:alpha-v-circle-outline"},
|
SENSOR_VOLTAGE: {ICON: "mdi:alpha-v-circle-outline"},
|
||||||
SENSOR_WEIGHT: {ICON: "mdi:scale"},
|
SENSOR_WEIGHT: {ICON: "mdi:scale"},
|
||||||
SENSOR_YESTERDAY: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
SENSOR_YESTERDAY: {DEVICE_CLASS: DEVICE_CLASS_POWER},
|
||||||
|
@ -738,7 +738,7 @@ hass-nabucasa==0.37.1
|
|||||||
hass_splunk==0.1.1
|
hass_splunk==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.tasmota
|
# homeassistant.components.tasmota
|
||||||
hatasmota==0.0.26
|
hatasmota==0.0.27
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.9.12
|
hdate==0.9.12
|
||||||
|
@ -376,7 +376,7 @@ hangups==0.4.11
|
|||||||
hass-nabucasa==0.37.1
|
hass-nabucasa==0.37.1
|
||||||
|
|
||||||
# homeassistant.components.tasmota
|
# homeassistant.components.tasmota
|
||||||
hatasmota==0.0.26
|
hatasmota==0.0.27
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.9.12
|
hdate==0.9.12
|
||||||
|
@ -4,8 +4,8 @@ from datetime import timedelta
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from hatasmota.utils import (
|
from hatasmota.utils import (
|
||||||
|
get_topic_stat_result,
|
||||||
get_topic_stat_status,
|
get_topic_stat_status,
|
||||||
get_topic_stat_switch,
|
|
||||||
get_topic_tele_sensor,
|
get_topic_tele_sensor,
|
||||||
get_topic_tele_will,
|
get_topic_tele_will,
|
||||||
)
|
)
|
||||||
@ -61,11 +61,15 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# Test normal state update
|
# Test normal state update
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1", '{"STATE":"ON"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"ON"}}'
|
||||||
|
)
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1", '{"STATE":"OFF"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"OFF"}}'
|
||||||
|
)
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
@ -80,13 +84,13 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
|
|
||||||
# Test polled state update
|
# Test polled state update
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass, "tasmota_49A3BC/stat/STATUS8", '{"StatusSNS":{"Switch1":"ON"}}'
|
hass, "tasmota_49A3BC/stat/STATUS10", '{"StatusSNS":{"Switch1":"ON"}}'
|
||||||
)
|
)
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass, "tasmota_49A3BC/stat/STATUS8", '{"StatusSNS":{"Switch1":"OFF"}}'
|
hass, "tasmota_49A3BC/stat/STATUS10", '{"StatusSNS":{"Switch1":"OFF"}}'
|
||||||
)
|
)
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
@ -141,13 +145,17 @@ async def test_off_delay(hass, mqtt_mock, setup_tasmota):
|
|||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert events == ["off"]
|
assert events == ["off"]
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1", '{"STATE":"ON"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"ON"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert events == ["off", "on"]
|
assert events == ["off", "on"]
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1", '{"STATE":"ON"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"ON"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("binary_sensor.test")
|
state = hass.states.get("binary_sensor.test")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
@ -195,7 +203,13 @@ async def test_availability_poll_state(
|
|||||||
config["swc"][0] = 1
|
config["swc"][0] = 1
|
||||||
poll_topic = "tasmota_49A3BC/cmnd/STATUS"
|
poll_topic = "tasmota_49A3BC/cmnd/STATUS"
|
||||||
await help_test_availability_poll_state(
|
await help_test_availability_poll_state(
|
||||||
hass, mqtt_client_mock, mqtt_mock, binary_sensor.DOMAIN, config, poll_topic, "8"
|
hass,
|
||||||
|
mqtt_client_mock,
|
||||||
|
mqtt_mock,
|
||||||
|
binary_sensor.DOMAIN,
|
||||||
|
config,
|
||||||
|
poll_topic,
|
||||||
|
"10",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -240,9 +254,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||||
config["swc"][0] = 1
|
config["swc"][0] = 1
|
||||||
topics = [
|
topics = [
|
||||||
get_topic_stat_switch(config, 0),
|
get_topic_stat_result(config),
|
||||||
get_topic_tele_sensor(config),
|
get_topic_tele_sensor(config),
|
||||||
get_topic_stat_status(config, 8),
|
get_topic_stat_status(config, 10),
|
||||||
get_topic_tele_will(config),
|
get_topic_tele_will(config),
|
||||||
]
|
]
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
|
@ -24,6 +24,44 @@ from tests.async_mock import ANY
|
|||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
|
"ip": "192.168.15.10",
|
||||||
|
"dn": "Tasmota",
|
||||||
|
"fn": ["Test", "Beer", "Milk", "Four", None],
|
||||||
|
"hn": "tasmota_49A3BC-0956",
|
||||||
|
"if": 0, # iFan
|
||||||
|
"lk": 1, # RGB + white channels linked to a single light
|
||||||
|
"mac": "00000049A3BC",
|
||||||
|
"md": "Sonoff Basic",
|
||||||
|
"ofln": "Offline",
|
||||||
|
"onln": "Online",
|
||||||
|
"state": ["OFF", "ON", "TOGGLE", "HOLD"],
|
||||||
|
"sw": "8.4.0.2",
|
||||||
|
"swn": [None, None, None, None, None],
|
||||||
|
"t": "tasmota_49A3BC",
|
||||||
|
"ft": "%topic%/%prefix%/",
|
||||||
|
"tp": ["cmnd", "stat", "tele"],
|
||||||
|
"rl": [0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
"swc": [-1, -1, -1, -1, -1, -1, -1, -1],
|
||||||
|
"btn": [0, 0, 0, 0],
|
||||||
|
"so": {
|
||||||
|
"4": 0, # Return MQTT response as RESULT or %COMMAND%
|
||||||
|
"11": 0, # Swap button single and double press functionality
|
||||||
|
"13": 0, # Allow immediate action on single button press
|
||||||
|
"17": 1, # Show Color string as hex or comma-separated
|
||||||
|
"20": 0, # Update of Dimmer/Color/CT without turning power on
|
||||||
|
"30": 0, # Enforce Home Assistant auto-discovery as light
|
||||||
|
"68": 0, # Multi-channel PWM instead of a single light
|
||||||
|
"73": 0, # Enable Buttons decoupling and send multi-press and hold MQTT messages
|
||||||
|
"82": 0, # Reduce the CT range from 153..500 to 200.380
|
||||||
|
"114": 0, # Enable sending switch MQTT messages
|
||||||
|
},
|
||||||
|
"ty": 0, # Tuya MCU
|
||||||
|
"lt_st": 0,
|
||||||
|
"ver": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_9_0_0_3 = {
|
||||||
"ip": "192.168.15.10",
|
"ip": "192.168.15.10",
|
||||||
"dn": "Tasmota",
|
"dn": "Tasmota",
|
||||||
"fn": ["Test", "Beer", "Milk", "Four", None],
|
"fn": ["Test", "Beer", "Milk", "Four", None],
|
||||||
|
@ -142,6 +142,7 @@ async def test_discover_bad_triggers(
|
|||||||
mac=None,
|
mac=None,
|
||||||
source=None,
|
source=None,
|
||||||
subtype=None,
|
subtype=None,
|
||||||
|
switchname=None,
|
||||||
trigger_topic=None,
|
trigger_topic=None,
|
||||||
type=None,
|
type=None,
|
||||||
)
|
)
|
||||||
@ -245,6 +246,7 @@ async def test_if_fires_on_mqtt_message(
|
|||||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||||
config["swc"][0] = 0
|
config["swc"][0] = 0
|
||||||
config["swc"][2] = 9
|
config["swc"][2] = 9
|
||||||
|
config["swn"][2] = "custom_switch"
|
||||||
mac = config["mac"]
|
mac = config["mac"]
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config))
|
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config))
|
||||||
@ -289,13 +291,17 @@ async def test_if_fires_on_mqtt_message(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data["some"] == "short_press"
|
assert calls[0].data["some"] == "short_press"
|
||||||
|
|
||||||
# Fake long press.
|
# Fake long press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH3T", '{"TRIG":"HOLD"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"custom_switch":{"Action":"HOLD"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
assert calls[1].data["some"] == "long_press"
|
assert calls[1].data["some"] == "long_press"
|
||||||
@ -314,6 +320,7 @@ async def test_if_fires_on_mqtt_message_late_discover(
|
|||||||
config2 = copy.deepcopy(DEFAULT_CONFIG)
|
config2 = copy.deepcopy(DEFAULT_CONFIG)
|
||||||
config2["swc"][0] = 0
|
config2["swc"][0] = 0
|
||||||
config2["swc"][3] = 9
|
config2["swc"][3] = 9
|
||||||
|
config2["swn"][3] = "custom_switch"
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config1))
|
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config1))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -361,13 +368,17 @@ async def test_if_fires_on_mqtt_message_late_discover(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data["some"] == "short_press"
|
assert calls[0].data["some"] == "short_press"
|
||||||
|
|
||||||
# Fake long press.
|
# Fake long press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH4T", '{"TRIG":"HOLD"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"custom_switch":{"Action":"HOLD"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
assert calls[1].data["some"] == "double_press"
|
assert calls[1].data["some"] == "double_press"
|
||||||
@ -414,7 +425,9 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -422,11 +435,15 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config2))
|
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config2))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/status/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/status/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
|
|
||||||
@ -434,11 +451,15 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config2))
|
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config2))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/status/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/status/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 3
|
assert len(calls) == 3
|
||||||
|
|
||||||
@ -527,7 +548,9 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -536,7 +559,9 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
|||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config))
|
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()
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -545,7 +570,9 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
|||||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config))
|
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()
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
|
|
||||||
@ -590,7 +617,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -598,7 +627,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||||||
device_reg.async_remove_device(device_entry.id)
|
device_reg.async_remove_device(device_entry.id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -637,7 +668,9 @@ async def test_attach_remove(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0] == "event 'tasmota_event'"
|
assert calls[0] == "event 'tasmota_event'"
|
||||||
@ -647,7 +680,9 @@ async def test_attach_remove(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify the triggers are no longer active
|
# Verify the triggers are no longer active
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -688,7 +723,9 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
@ -696,7 +733,9 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0] == "event 'tasmota_event'"
|
assert calls[0] == "event 'tasmota_event'"
|
||||||
@ -706,7 +745,9 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify the triggers are no longer active
|
# Verify the triggers are no longer active
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
@ -754,7 +795,9 @@ async def test_attach_remove_late2(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify the triggers is not active
|
# Verify the triggers is not active
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
@ -866,7 +909,9 @@ async def test_attach_remove_config_entry(hass, device_reg, mqtt_mock, setup_tas
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fake short press.
|
# Fake short press.
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0] == "event 'tasmota_event'"
|
assert calls[0] == "event 'tasmota_event'"
|
||||||
@ -877,6 +922,8 @@ async def test_attach_remove_config_entry(hass, device_reg, mqtt_mock, setup_tas
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify the triggers are no longer active
|
# Verify the triggers are no longer active
|
||||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/SWITCH1T", '{"TRIG":"TOGGLE"}')
|
async_fire_mqtt_message(
|
||||||
|
hass, "tasmota_49A3BC/stat/RESULT", '{"Switch1":{"Action":"TOGGLE"}}'
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
@ -6,7 +6,7 @@ from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
|||||||
from homeassistant.components.tasmota.discovery import ALREADY_DISCOVERED
|
from homeassistant.components.tasmota.discovery import ALREADY_DISCOVERED
|
||||||
|
|
||||||
from .conftest import setup_tasmota_helper
|
from .conftest import setup_tasmota_helper
|
||||||
from .test_common import DEFAULT_CONFIG
|
from .test_common import DEFAULT_CONFIG, DEFAULT_CONFIG_9_0_0_3
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
@ -132,6 +132,29 @@ async def test_device_discover(
|
|||||||
assert device_entry.sw_version == config["sw"]
|
assert device_entry.sw_version == config["sw"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_device_discover_deprecated(
|
||||||
|
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||||
|
):
|
||||||
|
"""Test setting up a device with deprecated discovery message."""
|
||||||
|
config = copy.deepcopy(DEFAULT_CONFIG_9_0_0_3)
|
||||||
|
mac = config["mac"]
|
||||||
|
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass,
|
||||||
|
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||||
|
json.dumps(config),
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Verify device and registry entries are created
|
||||||
|
device_entry = device_reg.async_get_device(set(), {("mac", mac)})
|
||||||
|
assert device_entry is not None
|
||||||
|
assert device_entry.manufacturer == "Tasmota"
|
||||||
|
assert device_entry.model == config["md"]
|
||||||
|
assert device_entry.name == config["dn"]
|
||||||
|
assert device_entry.sw_version == config["sw"]
|
||||||
|
|
||||||
|
|
||||||
async def test_device_update(
|
async def test_device_update(
|
||||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||||
):
|
):
|
||||||
|
@ -23,7 +23,7 @@ async def test_availability_poll_state_once(
|
|||||||
config["swc"][0] = 1
|
config["swc"][0] = 1
|
||||||
config["swc"][1] = 1
|
config["swc"][1] = 1
|
||||||
poll_payload_relay = ""
|
poll_payload_relay = ""
|
||||||
poll_payload_switch = "8"
|
poll_payload_switch = "10"
|
||||||
poll_topic_relay = "tasmota_49A3BC/cmnd/STATE"
|
poll_topic_relay = "tasmota_49A3BC/cmnd/STATE"
|
||||||
poll_topic_switch = "tasmota_49A3BC/cmnd/STATUS"
|
poll_topic_switch = "tasmota_49A3BC/cmnd/STATUS"
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
# Test polled state update
|
# Test polled state update
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass,
|
hass,
|
||||||
"tasmota_49A3BC/stat/STATUS8",
|
"tasmota_49A3BC/stat/STATUS10",
|
||||||
'{"StatusSNS":{"DHT11":{"Temperature":20.0}}}',
|
'{"StatusSNS":{"DHT11":{"Temperature":20.0}}}',
|
||||||
)
|
)
|
||||||
state = hass.states.get("sensor.tasmota_dht11_temperature")
|
state = hass.states.get("sensor.tasmota_dht11_temperature")
|
||||||
@ -169,7 +169,7 @@ async def test_nested_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
# Test polled state update
|
# Test polled state update
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass,
|
hass,
|
||||||
"tasmota_49A3BC/stat/STATUS8",
|
"tasmota_49A3BC/stat/STATUS10",
|
||||||
'{"StatusSNS":{"TX23":{"Speed":{"Act":"23.4"}}}}',
|
'{"StatusSNS":{"TX23":{"Speed":{"Act":"23.4"}}}}',
|
||||||
)
|
)
|
||||||
state = hass.states.get("sensor.tasmota_tx23_speed_act")
|
state = hass.states.get("sensor.tasmota_tx23_speed_act")
|
||||||
@ -214,7 +214,7 @@ async def test_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
# Test polled state update
|
# Test polled state update
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass,
|
hass,
|
||||||
"tasmota_49A3BC/stat/STATUS8",
|
"tasmota_49A3BC/stat/STATUS10",
|
||||||
'{"StatusSNS":{"ENERGY":{"TotalTariff":[5.6,7.8]}}}',
|
'{"StatusSNS":{"ENERGY":{"TotalTariff":[5.6,7.8]}}}',
|
||||||
)
|
)
|
||||||
state = hass.states.get("sensor.tasmota_energy_totaltariff_1")
|
state = hass.states.get("sensor.tasmota_energy_totaltariff_1")
|
||||||
@ -497,7 +497,7 @@ async def test_availability_poll_state(
|
|||||||
sensor.DOMAIN,
|
sensor.DOMAIN,
|
||||||
config,
|
config,
|
||||||
poll_topic,
|
poll_topic,
|
||||||
"8",
|
"10",
|
||||||
sensor_config,
|
sensor_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -559,7 +559,7 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||||
topics = [
|
topics = [
|
||||||
get_topic_tele_sensor(config),
|
get_topic_tele_sensor(config),
|
||||||
get_topic_stat_status(config, 8),
|
get_topic_stat_status(config, 10),
|
||||||
get_topic_tele_will(config),
|
get_topic_tele_will(config),
|
||||||
]
|
]
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user