mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Add Mqtt vacuum unknown
state (#65311)
* Add Mqtt vacuum `unknown` status * Update tests/components/mqtt/test_state_vacuum.py Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
cf52357229
commit
2f0d0998a2
@ -206,8 +206,12 @@ class MqttStateVacuum(MqttEntity, StateVacuumEntity):
|
||||
def state_message_received(msg):
|
||||
"""Handle state MQTT message."""
|
||||
payload = json.loads(msg.payload)
|
||||
if STATE in payload and payload[STATE] in POSSIBLE_STATES:
|
||||
self._state = POSSIBLE_STATES[payload[STATE]]
|
||||
if STATE in payload and (
|
||||
payload[STATE] in POSSIBLE_STATES or payload[STATE] is None
|
||||
):
|
||||
self._state = (
|
||||
POSSIBLE_STATES[payload[STATE]] if payload[STATE] else None
|
||||
)
|
||||
del payload[STATE]
|
||||
self._state_attrs.update(payload)
|
||||
self.async_write_ha_state()
|
||||
|
@ -235,6 +235,8 @@ async def test_status(hass, mqtt_mock):
|
||||
|
||||
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
message = """{
|
||||
"battery_level": 54,
|
||||
@ -262,6 +264,11 @@ async def test_status(hass, mqtt_mock):
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == "min"
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"]
|
||||
|
||||
message = '{"state":null}'
|
||||
async_fire_mqtt_message(hass, "vacuum/state", message)
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum when fan is not supported."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user