Skip to content

Commit

Permalink
Lock adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Dec 28, 2020
1 parent a60b75a commit 031e9c6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
7 changes: 5 additions & 2 deletions custom_components/sector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async def async_setup_entry(hass, entry):
)
await sector_data.async_update(force_update=True)
hass.data[DOMAIN] = sector_data
#unsub = entry.add_update_listener(update_listener)

device_registry = await dr.async_get_registry(hass)
device_registry.async_get_or_create(
Expand Down Expand Up @@ -167,6 +168,9 @@ async def async_setup_entry(hass, entry):

return True

#async def update_listener(hass, entry):
# """Handle options update."""

async def async_unload_entry(hass, entry):
"""Unload a config entry."""

Expand All @@ -179,6 +183,7 @@ async def async_unload_entry(hass, entry):
if sector_temp == True:
Platforms.append("sensor")

#unsub()
unload_ok = all(
await asyncio.gather(
*[
Expand Down Expand Up @@ -294,7 +299,6 @@ async def triggerlock(self, lock, code, command):
response = await self._request(API_URL + "/Panel/Lock", json_data=message_json)

await self.async_update(force_update=True)
return True

async def triggeralarm(self, command, code):

Expand All @@ -312,7 +316,6 @@ async def triggeralarm(self, command, code):
response = await self._request(API_URL + "/Panel/Disarm", json_data=message_json)

await self.async_update(force_update=True)
return True

async def async_update(self, force_update=False):
""" Fetch updates """
Expand Down
32 changes: 32 additions & 0 deletions custom_components/sector/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class SectorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

#@staticmethod
#def async_get_options_flow(config_entry):
# """Get the options flow for this handler."""
# return SectorOptionFlow(config_entry)

async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
Expand Down Expand Up @@ -121,6 +126,33 @@ async def async_step_user(self, user_input=None):
step_id="user", data_schema=DATA_SCHEMA, errors=errors,
)

#class SectorOptionFlow(config_entries.OptionsFlow):

# def __init__(self, config_entry):
# self.config_entry = config_entry
# self.options = dict(config_entry.options)

# async def async_step_init(self, user_input=None):
# """Manage the Sector options."""
# if user_input is not None:
# return self.async_create_entry(
# title=self.config_entry
# , data=user_input
# )

# return self.async_show_form(
# step_id="init",
# data_schema=vol.Schema(
# {
# vol.Required(
# "show_things",
# default=self.config_entry.options.get("show_things"),
# ): bool
# }
# ),
# )


class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""

Expand Down
46 changes: 18 additions & 28 deletions custom_components/sector/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,30 @@ async def async_update(self):
def is_locked(self):
return self._state == STATE_LOCKED

async def unlock(self, **kwargs):
async def async_unlock(self, **kwargs):
command = "unlock"
_LOGGER.debug("Sector: command is %s", command)
_LOGGER.debug("Sector: self._code is %s", self._code)
_LOGGER.debug("Lock: command is %s", command)
_LOGGER.debug("Lock: self._code is %s", self._code)
code = kwargs.get(ATTR_CODE, self._code)
_LOGGER.debug("Sector: code is %s", code)
_LOGGER.debug("Lock: code is %s", code)
if code is None:
_LOGGER.debug("Sector: No code supplied")
return False
_LOGGER.debug("Lock: No code supplied")
return

state = await self._hub.triggerlock(self._serial, code, command)
_LOGGER.debug("Sector: state is %s", state)
if state:
self._state = STATE_UNLOCKED
_LOGGER.debug("Sector: self._state is %s", self._state)
return True
await self._hub.triggerlock(self._serial, code, command)
_LOGGER.debug("Lock: Sent command to trigger lock")
self._state = STATE_LOCKED

return False

async def lock(self, **kwargs):
async def async_lock(self, **kwargs):
command = "lock"
_LOGGER.debug("Sector: command is %s", command)
_LOGGER.debug("Sector: self._code is %s", self._code)
_LOGGER.debug("Lock: command is %s", command)
_LOGGER.debug("Lock: self._code is %s", self._code)
code = kwargs.get(ATTR_CODE, self._code)
_LOGGER.debug("Sector: code is %s", code)
_LOGGER.debug("Lock: code is %s", code)
if code is None:
_LOGGER.debug("Sector: No code supplied")
return False
_LOGGER.debug("Lock: No code supplied")
return

state = await self._hub.triggerlock(self._serial, code, command)
_LOGGER.debug("Sector: state is %s", state)
if state:
self._state = STATE_LOCKED
_LOGGER.debug("Sector: self._state is %s", self._state)
return True

return False
await self._hub.triggerlock(self._serial, code, command)
_LOGGER.debug("Lock: Sent command to trigger lock")
self._state = STATE_UNLOCKED

0 comments on commit 031e9c6

Please sign in to comment.