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

Xiaomi aqara gateway alarm control #20294

Closed

Conversation

toribola
Copy link

@toribola toribola commented Jan 21, 2019

Description:

Arm/Disarm xiaomi aqara alarm

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

xiaomi_aqara:
  gateways:
    - mac: AA:BB:CC:DD:EE:FF
      key: 123456abcde
      token: 11223344556677889900aabbccddeeff 
alarm_control_panel:
    - platform: xiaomi_gateway
      host: 10.0.0.1
      token: 11223344556677889900aabbccddeeff 

Checklist:

  • [X ] The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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

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

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Contributor

Hi @toribola,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@frenck
Copy link
Member

frenck commented Jan 21, 2019

⚠️ I was unable to find a documentation PR (matching this code change) in our documentation repository.

📚Please, update the documentation and open a PR for it (be sure to create a documentation PR against the next branch) and link 🔗 this PR and the new documentation PR by mentioning the link to the PR's in both openings posts/descriptions.

🏷 I am adding the docs-missing label until this has been resolved.

👍 Thanks (times a million!)

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review, in order to get this merged the protocol-specific parts need to be moved into the upstream lib (see rytilahti/python-miio#470) and all references to xiaomi_aqara need to be removed.

from homeassistant.components.alarm_control_panel import AlarmControlPanel
import homeassistant.helpers.config_validation as cv
from homeassistant.components.switch import (PLATFORM_SCHEMA, )
from homeassistant.components.xiaomi_aqara import (CONF_HOST, CONF_TOKEN, )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import CONF_HOST and CONF_TOKEN from homeassistant.const instead of from xiaomi_aqara.

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Xiaomi Gateway Alarm'
DATA_KEY = 'alarm_control_panel.xiaomi_gateway'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alarm_control_panel.xiaomi_miio.

vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_TOKEN): vol.All(cv.string, vol.Length(min=32, max=32)),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_TURN_ON_COMMAND, default='set_arming'): cv.string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some specific reason to make this and turn_off configurable?

vol.All(cv.ensure_list, [cv.string]),
})

REQUIREMENTS = ['python-miio>=0.3.7']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be pinned on exact version, i.e. ==0.3.7.

"""Turn on."""
result = await self._try_command(
"Turning the miio device on failed.", self._device.send,
'set_arming', ['on'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be implemented in the backend lib, I just pushed my old code online if you are interested in working on it: rytilahti/python-miio#470

"""Turn off."""
result = await self._try_command(
"Turning the miio device off failed.", self._device.send,
'set_arming', ['off'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this needs to be done in the upstream library.


print(result)
if result:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug prints, do proper error handling if necessary.

'set_arming', ['off'])
print(result)
if result:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

try:
state = await self.hass.async_add_job(
self._device.send, 'get_arming', [self._state_property])
state = state.pop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be done in the upstream library.

@@ -285,6 +287,9 @@ def push_data(self, data, raw_data):
_LOGGER.debug("PUSH >> %s: %s", self, data)
was_unavailable = self._async_track_unavailable()
is_data = self.parse_data(data, raw_data)
print("=========================================================")
print(raw_data)
print("=========================================================")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all modifications and references to xiaomi_aqara. xiaomi_aqara implements the developer api access, xiaomi_miio is the correct one for this.

@balloob
Copy link
Member

balloob commented Feb 26, 2019

This PR seems to have gone stale. Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants