8000 Adds energy monitoring capabilities to the TP-Link HS110 by kirichkov · Pull Request #3917 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds energy monitoring capabilities to the TP-Link HS110 #39 8000 17

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

Merged
merged 5 commits into from
Oct 22, 2016

Conversation

kirichkov
Copy link
Contributor

Description:
Adds energy monitoring to the TP-Link HS110 Smart switches

Related issue (if applicable):

Pull request in home-assistant.github.io with documentation (if applicable):

Example entry for configuration.yaml (if applicable):

switch:
  - platform: tplink
    host: IP_ADRRESS

No changes to the configuration are needed. The updated module should automatically detect whether the switch's model and determine whether energy monitoring is available (HS110) or not (HS100)

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New 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:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

Energy monitoring works only on the HS110 model

Energy monitoring works only on the HS110 model
@mention-bot
Copy link

@kirichkov, thanks for your PR! By analyzing the history of the files in this pull request, we identified @GadgetReactor, @robbiet480 and @balloob to be potential reviewers.

@kirichkov
Copy link
Contributor Author
kirichkov commented Oct 17, 2016

Two notes to make:

  1. I haven't heard from the original developer of the pyHS100 module, so I created my own fork and created version 0.2.0 of the module.
  2. Currently the device_state_attributes will be polled irrespective of whether the switch supports energy monitoring or not. I couldn't figure out a way how to conditionally define device_state_attributes so it'd run only for the model that actually support energy monitoring, and not run for the model that doesn't support energy monitoring. I'm open to suggestions on how to optimize this.

@mweinelt
Copy link
Contributor
mweinelt commented Oct 18, 2016

Your fork introduces alot of mixed indentation and other style issues.

pyHS100/__init__.py:1:1: W391 blank line at end of file
pyHS100/pyHS100.py:1:80: E501 line too long (87 > 79 characters)
pyHS100/pyHS100.py:1:88: W291 trailing whitespace
pyHS100/pyHS100.py:3:80: E501 line too long (87 > 79 characters)
pyHS100/pyHS100.py:4:80: E501 line too long (94 > 79 characters)
pyHS100/pyHS100.py:58:11: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:61:11: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:97:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:98:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:101:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:107:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:107:80: E501 line too long (81 > 79 characters)
pyHS100/pyHS100.py:109:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:112:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:115:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:121:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:121:80: E501 line too long (81 > 79 characters)
pyHS100/pyHS100.py:123:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:126:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:127:1: W293 blank line contains whitespace
pyHS100/pyHS100.py:129:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:132:80: E501 line too long (90 > 79 characters)
pyHS100/pyHS100.py:135:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:138:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:140:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:143:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:144:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:146:36: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:146:38: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:146:74: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:146:76: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:146:80: E501 line too long (107 > 79 characters)
pyHS100/pyHS100.py:147:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:148:1: W293 blank line contains whitespace
pyHS100/pyHS100.py:150:80: E501 line too long (94 > 79 characters)
pyHS100/pyHS100.py:151:80: E501 line too long (96 > 79 characters)
pyHS100/pyHS100.py:154:80: E501 line too long (90 > 79 characters)
pyHS100/pyHS100.py:155:80: E501 line too long (94 > 79 characters)
pyHS100/pyHS100.py:157:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:160:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:160:80: E501 line too long (119 > 79 characters)
pyHS100/pyHS100.py:162:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:165:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:167:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:169:11: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:171:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:173:38: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:173:40: E251 unexpected spaces around keyword / parameter equals
pyHS100/pyHS100.py:174:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:177:80: E501 line too long (94 > 79 characters)
pyHS100/pyHS100.py:180:80: E501 line too long (90 > 79 characters)
pyHS100/pyHS100.py:181:80: E501 line too long (88 > 79 characters)
pyHS100/pyHS100.py:183:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:186:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:186:80: E501 line too long (94 > 79 characters)
pyHS100/pyHS100.py:188:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:191:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:193:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:195:11: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:197:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:198:1: W293 blank line contains whitespace
pyHS100/pyHS100.py:200:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:207:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:210:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:212:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:214:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:218:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:220:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:222:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:225:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:227:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:228:80: E501 line too long (105 > 79 characters)
pyHS100/pyHS100.py:231:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:232:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:233:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:233:23: W291 trailing whitespace
pyHS100/pyHS100.py:238:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:241:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:244:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:246:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:247:80: E501 line too long (105 > 79 characters)
pyHS100/pyHS100.py:248:80: E501 line too long (81 > 79 characters)
pyHS100/pyHS100.py:250:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:253:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:253:16: W291 trailing whitespace
pyHS100/pyHS100.py:254:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:255:7: E111 indentation is not a multiple of four
pyHS100/pyHS100.py:255:23: W291 trailing whitespace
pyHS100/pyHS100.py:257:21: W291 trailing whitespace

@balloob
Copy link
Member
balloob commented Oct 18, 2016

It looks like the original author has responded to your PR. Let's await his merging of your PR before we continue with this PR.

@GadgetReactor, since you are familiar with this code, would you mind reviewing this PR?

@kirichkov
Copy link
Contributor Author

My updates were merged into GadgetReactor's and most of the styling errors in the module should be resolved.

@mweinelt can you tell me what lint settings you're using, because I got different output when using the HASS pylintrc against the pyHS100/pyHS100.py codebase.

@GadgetReactor
Copy link
Contributor

From my end, the code looks good and tested with the HS100 with no issues.

@mweinelt
Copy link
Contributor

@kirichkov thats just the flake8 default.

@kirichkov
Copy link
Contributor Author

@balloob any possibility of getting this in for 0.31?

"""Return the state attributes of the device."""
_LOGGER.debug("Updating TP-Link energy meter data")

emeter_readings = self.smartplug.get_emeter_realtime()
Copy link
Member

Choose a reason for hiding this comment

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

You are not allowed to fetch data from an entity inside a property. Instead you should cache this data inside the update method.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if self.smartplug.state is also fetching data, but if it is, it too should be moved to update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, self.smartplug.state is used to fetch data from the plug. I moved everything to update and the state and the meter's values are now stored as class variables.

@balloob balloob self-assigned this Oct 21, 2016
@balloob balloob merged commit 4f6ed09 into home-assistant:dev Oct 22, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0