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

Conversation

cgarwood
Copy link
Member

@cgarwood cgarwood commented Dec 14, 2023

Proposed change

Adjust the handling of Fully Kiosk Browser MQTT event callbacks.
Fully Kiosk Browser allows you to set a custom MQTT topic for events. By default, this topic is: $appId/event/$event/$deviceId where $appId translates to fully, $event translates to the name of the event, and $deviceId is the ID of the device.

If a user configures a custom event topic without the $event placeholder, all of the events hit the same topic, so every event will trigger the callback regardless of what the event actually is.

The payload also contains the event name, so I adjusted the callback function to check that the event name in the payload is correct before firing the callback.

Tested with Fully Kiosk Browser 1.54.1 (current) and 1.42.5 and working.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@cgarwood cgarwood changed the title Fix Fully Kiosk Browser MQTT event callbacks with non-standard event topis Fix Fully Kiosk Browser MQTT event callbacks with non-standard event topics Dec 14, 2023
@cgarwood cgarwood added this to the 2023.12.3 milestone Dec 14, 2023
@@ -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.

@frenck frenck merged commit 40f9142 into home-assistant:dev Dec 14, 2023
23 checks passed
@frenck frenck mentioned this pull request Dec 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad behavior of Fully Kiosk Browser with the new 2023.12.0 HA core
3 participants