Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Fully Kiosk Browser MQTT event callbacks with non-standard event topics #105735

Merged
merged 2 commits into from Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/fully_kiosk/entity.py
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the mqtt data and topic parsing really belongs in the 3rd party library. Please move it there in a follow up PR. Have the library accept callbacks for subscription (and publishing) but do all the details in the library. Ie give the library handles to be able to use the MQTT transport of Home Assistant but keep the details about how those are used in the library.

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
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