|
|
|
|
@@ -493,6 +493,191 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
|
|
|
|
assert state.state == STATE_OFF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_controlling_state_via_mqtt_rgbww_hex(hass, mqtt_mock, setup_tasmota):
|
|
|
|
|
"""Test state update via MQTT."""
|
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
|
config["rl"][0] = 2
|
|
|
|
|
config["lt_st"] = 5 # 5 channel light (RGBCW)
|
|
|
|
|
config["so"]["17"] = 0 # Hex color in state updates
|
|
|
|
|
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_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("brightness") == 127.5
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"FF8000"}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"00FF800000"}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("rgb_color") == (0, 255, 128)
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("white_value") == 127.5
|
|
|
|
|
# Setting white > 0 should clear the color
|
|
|
|
|
assert not state.attributes.get("rgb_color")
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("color_temp") == 300
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
# Setting white to 0 should clear the white_value and color_temp
|
|
|
|
|
assert not state.attributes.get("white_value")
|
|
|
|
|
assert not state.attributes.get("color_temp")
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("effect") == "Cycle down"
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
|
|
|
|
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
|
|
|
|
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_OFF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
|
|
|
|
|
"""Test state update via MQTT."""
|
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
|
config["rl"][0] = 2
|
|
|
|
|
config["lt_st"] = 5 # 5 channel light (RGBCW)
|
|
|
|
|
config["ty"] = 1 # Tuya device
|
|
|
|
|
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_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Dimmer":50}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("brightness") == 127.5
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Color":"255,128,0"}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("rgb_color") == (255, 128, 0)
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":50}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("white_value") == 127.5
|
|
|
|
|
# Setting white > 0 should clear the color
|
|
|
|
|
assert not state.attributes.get("rgb_color")
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","CT":300}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("color_temp") == 300
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","White":0}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
# Setting white to 0 should clear the white_value and color_temp
|
|
|
|
|
assert not state.attributes.get("white_value")
|
|
|
|
|
assert not state.attributes.get("color_temp")
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
|
hass, "tasmota_49A3BC/tele/STATE", '{"POWER":"ON","Scheme":3}'
|
|
|
|
|
)
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
assert state.attributes.get("effect") == "Cycle down"
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"ON"}')
|
|
|
|
|
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"POWER":"OFF"}')
|
|
|
|
|
|
|
|
|
|
state = hass.states.get("light.test")
|
|
|
|
|
assert state.state == STATE_OFF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
|
|
|
|
|
"""Test the sending MQTT commands."""
|
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
|
@@ -745,6 +930,26 @@ async def test_transition(hass, mqtt_mock, setup_tasmota):
|
|
|
|
|
)
|
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
# Dim the light from 0->100: Speed should be capped at 40
|
|
|
|
|
await common.async_turn_on(hass, "light.test", brightness=255, transition=100)
|
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
|
"tasmota_49A3BC/cmnd/Backlog",
|
|
|
|
|
"NoDelay;Fade 1;NoDelay;Speed 40;NoDelay;Dimmer 100",
|
|
|
|
|
0,
|
|
|
|
|
False,
|
|
|
|
|
)
|
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
# Dim the light from 0->0: Speed should be 1
|
|
|
|
|
await common.async_turn_on(hass, "light.test", brightness=0, transition=100)
|
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
|
"tasmota_49A3BC/cmnd/Backlog",
|
|
|
|
|
"NoDelay;Fade 1;NoDelay;Speed 1;NoDelay;Power1 OFF",
|
|
|
|
|
0,
|
|
|
|
|
False,
|
|
|
|
|
)
|
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
# Dim the light from 0->50: Speed should be 4*2*2=16
|
|
|
|
|
await common.async_turn_on(hass, "light.test", brightness=128, transition=4)
|
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
|
|