Add aqara lock support#14419
Conversation
There was a problem hiding this comment.
line too long (85 > 79 characters)
|
Hi @SchumyHao, 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! |
There was a problem hiding this comment.
continuation line over-indented for visual indent
|
Please fix the lint errors. I'm very happy with your approach! |
|
I've released PyXiaomiGateway 0.9.2. Please update the requirements! |
|
Hi @syssi |
|
requirements_all.txt is not up to date |
Signed-off-by: SchumyHao <schumyhaojl@126.com>
Signed-off-by: SchumyHao <schumyhaojl@126.com>
Signed-off-by: SchumyHao <schumyhaojl@126.com>
Aqara lock can not read lock state. But After verify successfully, lock will be unlock state for about 5s. After 5s, lock will auto reset to lock state. Signed-off-by: SchumyHao <schumyhaojl@126.com>
| self._changed_by = int(value) | ||
| self._verified_wrong_times = 0 | ||
| self._state = STATE_UNLOCKED | ||
| async_call_later(self.hass, UNLOCK_MAINTAIN_TIME_S, |
| } | ||
| return attributes | ||
|
|
||
| @asyncio.coroutine |
There was a problem hiding this comment.
Make this a callback instead via the @callback decorator that can be imported from core.py.
There was a problem hiding this comment.
Could you care about this one, too?
There was a problem hiding this comment.
I'm not sure for this comment.
This function will be invoked in async_call_later, I need this function called after UNLOCK_MAINTAIN_TIME seconds. but callback function can not do IO operation, I think delay should not called in callback too.
There was a problem hiding this comment.
This function will be run with async_run_job. It's safe to run callbacks.
There was a problem hiding this comment.
I try to change this by using async_run_job, I tested this can work:
@@ -67,8 +68,10 @@ class XiaomiAqaraLock(LockDevice, XiaomiDevice):
return attributes
@asyncio.coroutine
- def clear_unlock_state(self, _):
+ def clear_unlock_state(self):
"""Clear unlock state automatically."""
+ yield from asyncio.sleep(UNLOCK_MAINTAIN_TIME)
+
self._state = STATE_LOCKED
self.async_schedule_update_ha_state()
@@ -85,8 +88,7 @@ class XiaomiAqaraLock(LockDevice, XiaomiDevice):
self._changed_by = int(value)
self._verified_wrong_times = 0
self._state = STATE_UNLOCKED
- async_call_later(self.hass, UNLOCK_MAINTAIN_TIME,
- self.clear_unlock_state)
+ self.hass.async_run_job(self.clear_unlock_state)
return True
return False
But I failed to using @callback
I have tried this
@@ -66,9 +67,12 @@ class XiaomiAqaraLock(LockDevice, XiaomiDevice):
}
return attributes
+ @callback
@asyncio.coroutine
- def clear_unlock_state(self, _):
+ def clear_unlock_state(self):
"""Clear unlock state automatically."""
+ yield from asyncio.sleep(UNLOCK_MAINTAIN_TIME)
+
self._state = STATE_LOCKED
self.async_schedule_update_ha_state()
@@ -85,8 +89,7 @@ class XiaomiAqaraLock(LockDevice, XiaomiDevice):
self._changed_by = int(value)
self._verified_wrong_times = 0
self._state = STATE_UNLOCKED
- async_call_later(self.hass, UNLOCK_MAINTAIN_TIME,
- self.clear_unlock_state)
+ self.hass.async_run_job(self.clear_unlock_state)
return True
But clear_unlock_state(self) will not invoked.
I'm sorry that how to use callback decorator, can you point me out how to do this?
There was a problem hiding this comment.
Hi @MartinHjelmare @syssi
May you help me to improve this code?
I have checked the code in homeassistant, which used async_call_later and callback, but do not find a similar usage in my situation.
There was a problem hiding this comment.
Just change this line to @callback.
There was a problem hiding this comment.
Done.
Thank you for your advice
| UNLOCK_MAINTAIN_TIME_S = 5 | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): |
There was a problem hiding this comment.
This should be made a coroutine via async def to make the call to async_call_later in parse_data, which will be called during entity init, work. I assume the rest of the calls in the base entity XiaomiDevice can be done safely from an async context?
Signed-off-by: SchumyHao <schumyhaojl@126.com>
Signed-off-by: SchumyHao <schumyhaojl@126.com>
Signed-off-by: SchumyHao <schumyhaojl@126.com>
|
Could you add some docs? |
|
OK, I'll do this job. |
|
I added some basic docs: home-assistant/home-assistant.io#5387 |
|
Thank you @syssi |
|
I'm not sure what should I do in next step? |
|
I'm waiting for an review/approval of the docs. As far as the docs are approved I will merge this PR. |
|
Thank you @syssi. Please let me know if I need do something more. |
Signed-off-by: SchumyHao schumyhaojl@126.com
Description:
Add aqara lock support
Related issue (if applicable): fixes #
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: