Open danobot opened 6 years ago
Same issue here
The issue would seem to be the syntax changes for async functions in .82. I was able to avoid the bug by updating as follows:
--- tmp\bwalarm.py 2018-11-12 21:47:39.000000000 -0800
+++ bwalarm.py 2018-11-13 00:12:27.000000000 -0800
@@ -214,14 +214,13 @@
vol.Optional(CONF_OVERRIDE_CODE, default=False): cv.boolean,
#-----------------------------END------------------------------------
}, _state_validator))
_LOGGER = logging.getLogger(__name__)
-@asyncio.coroutine
-def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
+async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
#Setup MQTT if enabled
mqtt = None
if (config[CONF_MQTT]):
import homeassistant.components.mqtt as mqtt
alarm = BWAlarm(hass, config, mqtt)
hass.bus.async_listen(EVENT_STATE_CHANGED, alarm.state_change_listener)
@@ -638,14 +637,13 @@
if now() > self._passcode_timeoutat:
self._panel_locked = False
self._passcode_timeoutat = None
self._passcodeAttemptNo = 0
self.schedule_update_ha_state()
- @asyncio.coroutine
- def async_added_to_hass(self):
+ async def async_added_to_hass(self):
"""Subscribe mqtt events.
This method must be run in the event loop and returns a coroutine.
"""
if (self._mqtt):
async_track_state_change(
self.hass, self.entity_id, self._async_state_changed_listener
@@ -672,13 +670,12 @@
_LOGGER.warning("[ALARM/MQTT] Received unexpected payload: %s", payload)
return
if (self._mqtt):
return self.mqtt.async_subscribe(
self.hass, self._command_topic, message_received, self._qos)
- @asyncio.coroutine
- def _async_state_changed_listener(self, entity_id, old_state, new_state):
+ async def _async_state_changed_listener(self, entity_id, old_state, new_state):
"""Publish state change to MQTT."""
if (self._mqtt):
self.mqtt.async_publish(self.hass, self._state_topic, new_state.state,
self._qos, True)
_LOGGER.debug("[ALARM/MQTT] State changed")
@adipose Are you able to PR this fix? Happy to test on my system as well
@danobot I could do that, but I have to be honest: my alarm is not updating when the mqtt messages arrive. I believe my update is correct, insofar as the new syntax for async has changed. If this change is not made, HA will not even boot because it gets stuck in the event loop.
What's very strange, though, is the manual_mqtt alarm does not have the async_setup_platform set up as an async method. Everywhere else in the code base async_setup_platform is type async, except for manual_mqtt. Thus I speculated that bwalarm would also need to be non-async, but doing that results in the hang of HA.
I will PR my fix, if I get mqtt working. For now, if you want to use my patch, you simply need to edit your bwalarm.py and remove all the lines that say:
@asyncio.coroutine
Then the "def" that immediately follows should be prefixed with "async."
It's working now.
https://github.com/gazoscalvertos/Hass-Custom-Alarm/pull/52
I had to turn all the internal calls to async_ but leave the outer async_setup_platform without the async prefix.
It's working now with override_code aswell.
I needed that since my mqtt alarm panel doesn't have code for arming, only for disarming.
Hi, I am on HA v0.81.0 and bwalarm v1.0.4.
When sending an MQTT message to arm the alarm, I am getting this error in the logs:
The MQTT message is send from within a script:
My configuration is based on the default:
Can confirm the
alarm_disarm
script works as expected. Calling thealarm_arm_away
script causes this error. Tried isolating the problem as well by calling the MQTT publish service directly using these parameters:Same error:
This is a critical error because HA is unable to recognise the alarm panel afterwards. (the following log is generated when clicking on the ARM Away button in the alarm panel frontend.