-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
More support for availability reporting on MQTT components #11336
More support for availability reporting on MQTT components #11336
Conversation
tests/components/fan/test_mqtt.py
Outdated
|
||
from homeassistant.setup import setup_component | ||
from homeassistant.components import fan | ||
from homeassistant.const import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'homeassistant.const.STATE_ON' imported but unused
'homeassistant.const.STATE_OFF' imported but unused
72d92d1
to
1761cd7
Compare
"""Init the MQTT Alarm Control Panel.""" | ||
super(MqttAlarm, self).__init__( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use python 3 style call:
super().__init__(...)
@@ -89,7 +99,7 @@ def message_received(topic, payload, qos): | |||
self._state = payload | |||
self.async_schedule_update_ha_state() | |||
|
|||
return mqtt.async_subscribe( | |||
yield from mqtt.async_subscribe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but it is required now as multiple topics can be subscribed (status and availability).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, for clarity I think we should add the @asyncio.coroutine
annotation to all async_added_to_hass
methods in the entity classes affected by this PR. I think that should have been done previously, so if you can do that it's 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update the docstrings for these methods. Ie they don't return a coroutine object anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My last comment came out weird, of course the coroutine function will still return a coroutine object but it doesn't explicitly return something, so I think we can remove the last sentence in the docstring.
payload_not_available): | ||
"""Initialize the MQTT binary sensor.""" | ||
self._availability_topic = availability_topic | ||
self._available = True if availability_topic is None else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._available = availability_topic is None
- Moved availability topic and payloads to MQTT base schema. - Updated components that already report availability: - Switch - Binary sensor - Cover
- Light - JSON light - Template light - Lock - Fan - HVAC - Sensor - Vacuum - Alarm control panel
1761cd7
to
e22ff6c
Compare
Please don't squash after PR review has started. It makes it harder to follow changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I think we can merge when tests pass.
@MartinHjelmare Cool, I'm just getting the documentation ready now. Also this changes the default values for availability payloads for the MQTT Switch platform, would that be enough to warrant this being a breaking change? |
Great! Yes, let's add the breaking change tag to be clear. Please add a paragraph in the description what has changed that is breaking. |
To accompany changes from: home-assistant/core#11336 Updated platforms: - Switch (previously supported) - Binary sensor (previously supported) - Cover (previously supported) - Light - JSON light - Template light - Sensor - Alarm control panel - Lock - HVAC - Fan - Vacuum
config.get(CONF_CODE), | ||
config.get(CONF_AVAILABILITY_TOPIC), | ||
config.get(CONF_PAYLOAD_AVAILABLE), | ||
config.get(CONF_PAYLOAD_NOT_AVAILABLE))]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying it right now, my alarm is always showing as unavailable. I think you missed the .extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema)
. Can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I saw the unit test, this is very surprising. I will test this further but it seems it sees the availability_topic
in my config (as it shows the alarm as unavailable) but doesn't get the value from it (which is "online"). The message is properly retained, checked with mosquitto_sub.
Here is my config:
alarm_control_panel:
platform: mqtt
state_topic: home/alarm
command_topic: home/alarm/set
availability_topic: home/alarm/availability
Maybe the unit test somehow bypass some config validation? /cc @balloob
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I've tested with this config:
alarm_control_panel:
platform: mqtt
state_topic: home/alarm
command_topic: home/alarm/set
availability_topic: home/alarm/availability
payload_available: online
payload_not_available: offline
And it works perfectly.
My guess is that without the schema extension, the component isn't able to get default values for the config variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. That makes sense. Without the schema the values for the payloads will both be None
.
For the sake of completeness I'll add some extra tests for the default payloads in #11829.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your quick response and fixes!
@DanNixon Please correct me if I'm wrong, but I believe you forgot to delete the availability topic subscription in the cover component. See https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/cover/mqtt.py#L218 and line 235. |
@OttoWinter Yes, it looks that way. Thanks for spotting. I'm a little busy for the time being but I can have a look and correct it in a couple of days. |
Description:
Adds the ability to use alive and LWT messages to set the availability of the majority of MQTT devices and abstracts the logic for handling availability topics to a mixin
MqttAvailability
.The following components now support availability:
Breaking changes:
The default availability payloads for the MQTT Switch platform have changed from "ON" and "OFF" to "online" and "offline" (in order to match the majority of MQTT platforms that already supported availability reporting).
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4293
Example entry for
configuration.yaml
(if applicable):The last three variables are the important ones, they can be added to the configuration of any of the components mentioned above.
Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests pass