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

#49 Fixing so we can set all states from MQTT #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions custom_components/alarm_control_panel/bwalarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ def _state_schema():
except Exception as e:
_LOGGER.warning('Import Error: %s. Attempting to download and import', e)

@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
Expand Down Expand Up @@ -918,7 +917,6 @@ def passcode_timeout_listener(self, eventignored):
self._passcodeAttemptNo = 0
self.schedule_update_ha_state()

@asyncio.coroutine
def async_added_to_hass(self):
"""Subscribe mqtt events.
This method must be run in the event loop and returns a coroutine.
Expand All @@ -936,24 +934,32 @@ def message_received(topic, payload, qos):
#_LOGGER.warning("Disarming %s", payload)
#TODO self._hass.states.get('binary_sensor.siren_sensor') #Use this method to relay open states
if (self._override_code):
self.alarm_disarm(self._code)
self.async_alarm_disarm(self._code)
else:
self.alarm_disarm(payload.split(" ")[1])
self.async_alarm_disarm(payload.split(" ")[1])
elif payload == self._payload_arm_home:
self.alarm_arm_home('')
if (self._override_code):
self.async_alarm_arm_home(self._code)
else:
self.async_alarm_arm_home('override')
elif payload == self._payload_arm_away:
self.alarm_arm_away('')
if (self._override_code):
self.async_alarm_arm_away(self._code)
else:
self.async_alarm_arm_away('')
elif payload == self._payload_arm_night:
self.alarm_arm_night('')
if (self._override_code):
self.async_alarm_arm_night(self._code)
else:
self.async_alarm_arm_night('')
else:
_LOGGER.warning("[ALARM/MQTT] Received unexpected payload: %s", payload)
return
if (self._config[CONF_MQTT][CONF_ENABLE_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._config[CONF_MQTT][CONF_ENABLE_MQTT]):
state = new_state.state
Expand Down