Fix Tasmota relay acting as on/off light (#42259)
parent
5bba299e8f
commit
88231aa541
|
@ -3,7 +3,7 @@
|
|||
"name": "Tasmota (beta)",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/tasmota",
|
||||
"requirements": ["hatasmota==0.0.20"],
|
||||
"requirements": ["hatasmota==0.0.21"],
|
||||
"dependencies": ["mqtt"],
|
||||
"mqtt": ["tasmota/discovery/#"],
|
||||
"codeowners": ["@emontnemery"]
|
||||
|
|
|
@ -732,7 +732,7 @@ hass-nabucasa==0.37.1
|
|||
hass_splunk==0.1.1
|
||||
|
||||
# homeassistant.components.tasmota
|
||||
hatasmota==0.0.20
|
||||
hatasmota==0.0.21
|
||||
|
||||
# homeassistant.components.jewish_calendar
|
||||
hdate==0.9.5
|
||||
|
|
|
@ -367,7 +367,7 @@ hangups==0.4.11
|
|||
hass-nabucasa==0.37.1
|
||||
|
||||
# homeassistant.components.tasmota
|
||||
hatasmota==0.0.20
|
||||
hatasmota==0.0.21
|
||||
|
||||
# homeassistant.components.jewish_calendar
|
||||
hdate==0.9.5
|
||||
|
|
|
@ -277,7 +277,39 @@ async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
config["so"]["30"] = 1 # Enforce Home Assistant auto-discovery as light
|
||||
mac = config["mac"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
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("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"OFF"}')
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -344,7 +376,47 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("effect") == "Cycle down"
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
config["so"]["30"] = 1 # Enforce Home Assistant auto-discovery as light
|
||||
mac = config["mac"]
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||
json.dumps(config),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Turn the light on and verify MQTT message is sent
|
||||
await common.async_turn_on(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog", "NoDelay;Fade 0;NoDelay;Power1 ON", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
# Tasmota is not optimistic, the state should still be off
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# Turn the light off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "light.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/Backlog", "NoDelay;Fade 0;NoDelay;Power1 OFF", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
|
|
@ -80,7 +80,7 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||
# Turn the switch on and verify MQTT message is sent
|
||||
await common.async_turn_on(hass, "switch.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/POWER1", "ON", 0, False
|
||||
"tasmota_49A3BC/cmnd/Power1", "ON", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
@ -91,7 +91,7 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||
# Turn the switch off and verify MQTT message is sent
|
||||
await common.async_turn_off(hass, "switch.test")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tasmota_49A3BC/cmnd/POWER1", "OFF", 0, False
|
||||
"tasmota_49A3BC/cmnd/Power1", "OFF", 0, False
|
||||
)
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
|
|
Loading…
Reference in New Issue