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

Fix niko_home_control integration #23093

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

NoUseFreak
Copy link
Contributor

@NoUseFreak NoUseFreak commented Apr 14, 2019

Breaking Change:

No breaking changes

Description:

Update base library and only pull for state once.

Related issue: fixes #20005 and #19283

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

Checklist:

  • 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:

  • The manifest file has all fields filled out correctly (example).
  • New dependencies have been added to requirements in the manifest (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.

@NoUseFreak
Copy link
Contributor Author

Can I get some assistance in getting the build green :-)

Also, just want to make sure, the package I depend on has it's own dependencies, should these be listed in the manifests?

@codecov
Copy link

codecov bot commented Apr 14, 2019

Codecov Report

Merging #23093 into dev will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #23093      +/-   ##
==========================================
+ Coverage   93.95%   93.97%   +0.01%     
==========================================
  Files         452      450       -2     
  Lines       36788    36878      +90     
==========================================
+ Hits        34566    34656      +90     
  Misses       2222     2222
Impacted Files Coverage Δ
homeassistant/components/mqtt/vacuum.py 92.46% <0%> (-1.92%) ⬇️
homeassistant/components/mqtt/climate.py 99.49% <0%> (-0.51%) ⬇️
homeassistant/components/websocket_api/http.py 89.34% <0%> (-0.18%) ⬇️
homeassistant/util/yaml.py 94.33% <0%> (-0.06%) ⬇️
homeassistant/components/mqtt/discovery.py 97.89% <0%> (-0.05%) ⬇️
homeassistant/loader.py 94.31% <0%> (-0.03%) ⬇️
homeassistant/components/rflink/light.py 100% <0%> (ø) ⬆️
homeassistant/components/deconz/switch.py 100% <0%> (ø) ⬆️
homeassistant/components/litejet/switch.py 100% <0%> (ø) ⬆️
homeassistant/components/mqtt/binary_sensor.py 100% <0%> (ø) ⬆️
... and 130 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c314220...3d4fc29. Read the comment docs.

@NoUseFreak NoUseFreak force-pushed the fix-niko-home-control branch 3 times, most recently from 01887cc to 71e450e Compare April 14, 2019 21:25
@awarecan
Copy link
Contributor

You don't need specific other upstream lib, unless they are not pip-installed along with niko-home-control==0.2.0

Copy link
Contributor

@awarecan awarecan left a comment

Choose a reason for hiding this comment

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

There is also a new pull request #23105 coming, what are the different between these two? Can you guys cooperate?

homeassistant/components/niko_home_control/light.py Outdated Show resolved Hide resolved
@NoUseFreak NoUseFreak force-pushed the fix-niko-home-control branch 2 times, most recently from 2573332 to a5891d5 Compare April 15, 2019 06:41
@codecov

This comment has been minimized.

@NoUseFreak
Copy link
Contributor Author

@awarecan I still have an issue where when I turn on a light, it takes a while for the state to be updated to the correct value. Should I be setting the state in the turn_on and turn_off methods?

It looks kind of weird if you want to turn something on and off again you have to click it multiple times before it turns off.

@awarecan
Copy link
Contributor

You can set state in turn_on/off method, if you enabled assumed_state. We have tons of light/switch do this, we call it 'optimistic updates'

@NoUseFreak
Copy link
Contributor Author

@awarecan Any way I can force a fetch after a state has changed in HA, I tried the assumed_state but it also did not update the state until a new fetch was done (30 sec later)

@awarecan
Copy link
Contributor

awarecan commented Apr 15, 2019

assumed_state won't help you update the state, you need update state by yourself. See following example
https://github.com/home-assistant/home-assistant/blob/ec171b99286b52f9178fc15bade83d1cb7abe5dd/homeassistant/components/mysensors/switch.py#L137-L140

@NoUseFreak NoUseFreak force-pushed the fix-niko-home-control branch 3 times, most recently from b487ea6 to 8cfeb29 Compare April 15, 2019 17:39
@NoUseFreak
Copy link
Contributor Author

I'll focus on refactoring the underlying logic to provide a way to listen to the controller events on a later time. I first want my lights to turn on again. :-)
Any good examples you know off that have something like a callback function to update state from a long-running poller function?

@NoUseFreak NoUseFreak force-pushed the fix-niko-home-control branch 2 times, most recently from 302e30c to 2c29b75 Compare April 16, 2019 07:26
@codecov
Copy link

codecov bot commented Apr 16, 2019

Codecov Report

Merging #23093 into dev will decrease coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              dev   #23093     +/-   ##
=========================================
- Coverage   94.15%   93.96%   -0.2%     
=========================================
  Files         452      452             
  Lines       36809    36788     -21     
=========================================
- Hits        34658    34567     -91     
- Misses       2151     2221     +70
Impacted Files Coverage Δ
homeassistant/components/demo/sensor.py 0% <0%> (-100%) ⬇️
homeassistant/components/demo/binary_sensor.py 0% <0%> (-100%) ⬇️
homeassistant/components/demo/device_tracker.py 21.42% <0%> (-78.58%) ⬇️
homeassistant/components/hassio/ingress.py 67.76% <0%> (-10.29%) ⬇️
homeassistant/components/axis/device.py 93.02% <0%> (-6.98%) ⬇️
homeassistant/components/deconz/config_flow.py 97.77% <0%> (-2.23%) ⬇️
homeassistant/components/axis/camera.py 90.24% <0%> (-0.67%) ⬇️
...assistant/components/manual/alarm_control_panel.py 98.11% <0%> (-0.63%) ⬇️
homeassistant/components/google_assistant/trait.py 96.14% <0%> (-0.47%) ⬇️
homeassistant/bootstrap.py 58.78% <0%> (-0.24%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7102ea...2c29b75. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 16, 2019

Codecov Report

Merging #23093 into dev will decrease coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              dev   #23093     +/-   ##
=========================================
- Coverage   94.15%   93.96%   -0.2%     
=========================================
  Files         452      452             
  Lines       36809    36788     -21     
=========================================
- Hits        34658    34567     -91     
- Misses       2151     2221     +70
Impacted Files Coverage Δ
homeassistant/components/demo/sensor.py 0% <0%> (-100%) ⬇️
homeassistant/components/demo/binary_sensor.py 0% <0%> (-100%) ⬇️
homeassistant/components/demo/device_tracker.py 21.42% <0%> (-78.58%) ⬇️
homeassistant/components/hassio/ingress.py 67.76% <0%> (-10.29%) ⬇️
homeassistant/components/axis/device.py 93.02% <0%> (-6.98%) ⬇️
homeassistant/components/deconz/config_flow.py 97.77% <0%> (-2.23%) ⬇️
homeassistant/components/axis/camera.py 90.24% <0%> (-0.67%) ⬇️
...assistant/components/manual/alarm_control_panel.py 98.11% <0%> (-0.63%) ⬇️
homeassistant/components/google_assistant/trait.py 96.14% <0%> (-0.47%) ⬇️
homeassistant/bootstrap.py 58.78% <0%> (-0.24%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7102ea...d0821e3. Read the comment docs.

Update base library and only pull for state once.
@NoUseFreak
Copy link
Contributor Author

@awarecan Anything else I should do before it can be merged?

@awarecan awarecan merged commit 45e5f5d into home-assistant:dev Apr 16, 2019
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please open a new PR where we can address the comments.


PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL): cv.time_period,
Copy link
Member

Choose a reason for hiding this comment

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

This is already part of the base platform schema.

self._brightness = None
_LOGGER.debug("Init new light: %s", light.name)
Copy link
Member

Choose a reason for hiding this comment

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

We try to avoid side effects in init method. Move the logging out of init.

return self._unique_id

@property
def device_info(self):
Copy link
Member

Choose a reason for hiding this comment

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

device_info property is only read if the platform is loaded via config entry.

https://developers.home-assistant.io/docs/en/device_registry_index.html#defining-devices

@@ -64,16 +92,52 @@ def is_on(self):
"""Return true if light is on."""
return self._state

def turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Why change to async api? The device library doesn't support asyncio.


def get_state(self, aid):
"""Find and filter state based on action id."""
return next(filter(lambda a: a['id'] == aid, self.data))['value1'] != 0
Copy link
Member

Choose a reason for hiding this comment

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

Don't use filter + lambda. Use a generator expression.

@NoUseFreak
Copy link
Contributor Author

@MartinHjelmare I fixed your feedback in #23176 together with upgrading the library version to make sure it installs it's dependencies.

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.

Error setting up Niko Home Control Component
4 participants