Skip to content

Commit

Permalink
Fix Fully Kiosk Browser MQTT event callbacks with non-standard event …
Browse files Browse the repository at this point in the history
…topics (#105735)
  • Loading branch information
cgarwood authored and frenck committed Dec 14, 2023
1 parent 25bfe7e commit 4aa03b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/fully_kiosk/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ async def mqtt_subscribe(
@callback
def message_callback(message: mqtt.ReceiveMessage) -> None:
payload = json.loads(message.payload)
event_callback(**payload)
if "event" in payload and payload["event"] == event:
event_callback(**payload)

topic_template = data["settings"]["mqttEventTopic"]
topic = (
topic_template.replace("$appId", "fully")
.replace("$event", event)
.replace("$deviceId", data["deviceID"])
)

return await mqtt.async_subscribe(self.hass, topic, message_callback)
24 changes: 20 additions & 4 deletions tests/components/fully_kiosk/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,35 @@ async def test_switches_mqtt_update(
assert entity
assert entity.state == "on"

async_fire_mqtt_message(hass, "fully/event/onScreensaverStart/abcdef-123456", "{}")
async_fire_mqtt_message(
hass,
"fully/event/onScreensaverStart/abcdef-123456",
'{"deviceId": "abcdef-123456","event": "onScreensaverStart"}',
)
entity = hass.states.get("switch.amazon_fire_screensaver")
assert entity.state == "on"

async_fire_mqtt_message(hass, "fully/event/onScreensaverStop/abcdef-123456", "{}")
async_fire_mqtt_message(
hass,
"fully/event/onScreensaverStop/abcdef-123456",
'{"deviceId": "abcdef-123456","event": "onScreensaverStop"}',
)
entity = hass.states.get("switch.amazon_fire_screensaver")
assert entity.state == "off"

async_fire_mqtt_message(hass, "fully/event/screenOff/abcdef-123456", "{}")
async_fire_mqtt_message(
hass,
"fully/event/screenOff/abcdef-123456",
'{"deviceId": "abcdef-123456","event": "screenOff"}',
)
entity = hass.states.get("switch.amazon_fire_screen")
assert entity.state == "off"

async_fire_mqtt_message(hass, "fully/event/screenOn/abcdef-123456", "{}")
async_fire_mqtt_message(
hass,
"fully/event/screenOn/abcdef-123456",
'{"deviceId": "abcdef-123456","event": "screenOn"}',
)
entity = hass.states.get("switch.amazon_fire_screen")
assert entity.state == "on"

Expand Down

0 comments on commit 4aa03b3

Please sign in to comment.