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

added smappee component #11491

Merged
merged 22 commits into from Feb 18, 2018

Conversation

Projects
None yet
7 participants
@hmn
Copy link
Contributor

commented Jan 6, 2018

Description:

Added components for https://www.smappee.com/

Example entry for configuration.yaml (if applicable):

smappee:
    host: 10.0.0.5
    client_id: YOUR_CLIENT_ID
    client_secret: YOUR_CLIENT_SECRET
    username: YOUR_MYSMAPPEE_USERNAME
    password: YOUR_MYSMAPPEE_PASSWORD

Checklist:

  • The code change is tested and works locally.

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][ex-requir]).
  • New dependencies are only imported inside functions that use them ([example][ex-import]).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

ciotlosm and others added some commits Jan 6, 2018

Merge pull request #1 from ciotlosm/smappee
Fixed pylint errors and a few use cases when starting up with invalid…

ciotlosm and others added some commits Jan 7, 2018

Added support to run only locally
Added a few more sensors
Added more error handling

Better parsing and debug message
Merge pull request #2 from ciotlosm/smappee
Added support to run only locally

hmn and others added some commits Jan 7, 2018

Merge branch 'dev' into smappee
* dev:
  upgrade schiene to 0.20 (#11504)
  Upgrade pywebpush to 1.5.0 (#11497)
  Fix time functions would throw errors in python scripts (#11414)
  Clean up Alexa.intent and DialogFlow.intent (#11492)
  Add missing configuration variables (#11390)
  Add new iGlo component (#11171)
  Upgrade pysnmp to 4.4.4 (#11485)
Merge branch 'dev' into smappee
* dev:
  Address missed review comments for Dark Sky weather (#11520)
  Fix canary flaky test (#11519)
  Lazy loading of service descriptions (#11479)
  Add Dark Sky weather component (#11435)
  Snips (new) added speech response, parse snips/duration (#11513)
  More tolerant KNX component if gateway cant be connected (#11511)
  timer: include the remaining time in the state attributes (#11510)
Merge branch 'dev' into smappee
* dev:
  Reconnect before mochad switch send command (#11296)
  New features for Owntracks device_tracker (#11480)
Smappee - update switches for local support (#3)
* Merged with local version

* Updated smappy library with the patched one

Fixed lint, added merge missing param

Fixed missing run for requirements_all.txt

Fixed lint

* Fixed on/off based on library. Reverted change used for testing stacktrace

* Fixed switches to work with both remote and local active

Fixed lint

Fixed switches

Fixed lint
@@ -0,0 +1,290 @@
"""
Support for Digital Ocean.

This comment has been minimized.

Copy link
@gieljnssns

gieljnssns Jan 12, 2018

Contributor

Shouldn't this be Smappee

hmn added some commits Jan 15, 2018

Merge branch 'dev' into smappee
* dev: (85 commits)
  Bump dev to 0.62.0.dev0 (#11652)
  Add Deconz support for Zigbee green power devices like Hue Tap (#11455)
  Update Pyarlo to 0.1.2 (#11626)
  Use kelvin/mireds correctly for setting iglo white (#11622)
  patch stop command (#11612)
  Upgrade yarl to 0.18.0 (#11609)
  Xiaomi lib upgrade (#11603)
  Bugfix and cleanup for Rfxtrx (#11600)
  Concord232 alarm arm away fix (#11597)
  Snips add say and say_actions services (new) (#11596)
  Fix state for trigger with forced updates (#11595)
  Pushbullet email support (fix) (#11590)
  Fix Tahoma stop command for 2 types of shutters (#11588)
  Core support for hass.io calls & Bugfix check_config (#11571)
  Avoid returning empty media_image_url string (#11557)
  Upgrade coinmarketcap to 4.1.2 (#11634)
  Update CODEOWNERS
  Add templates to MQTT climate (#11623)
  upgrade xiaomi lib (#11629)
  Fixes and enhancements for the Tahoma platform (#11547)
  ...
@dcsg

This comment has been minimized.

Copy link

commented Feb 2, 2018

+1

self._state = round(power, 2)
self._timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
else:
return None

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Remove this. Does nothing.

"""Get switches from local Smappee."""
if self.is_local_active:
return self._localsmappy.load_command_control_config()
return False

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Inconsistent return type

_LOGGER.error(
"Error getting comsumption from Smappee cloud. (%s)",
error)
return False

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Inconsistent return type

self._timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self._state = round(consumption.get('solar') / 1000, 2)
elif self._sensor == 'power_today':
data = self._smappee.get_consumption(

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

There is no error handling being done here. This method can return False.

# 3 = daily values,
# 4 = monthly values,
# 5 = quarterly values
if self.is_remote_active:

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Use guard clause

if not self.is_remote_active:
    return

end =
# 3 = daily values,
# 4 = monthly values,
# 5 = quarterly values
if self.is_remote_active:

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

guard clause

error)
return False

return False

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

These error values are never handled. Probably better to propagate the error to the update method of the sensor.

self._smappy.actuator_on(location_id, actuator_id, duration)
else:
self._localsmappy.on_command_control(actuator_id)
return True

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Inconsistent return


def instantaneous_values(self):
"""ReportInstantaneousValues."""
if self.is_local_active:

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

guard clause

# Skip local switches if remote available
if not smappee.is_remote_active:
local_devices = smappee.local_devices
if smappee.is_local_active:

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Merge with parent if statement.


def turn_on(self, **kwargs):
"""Turn on Comport Plug."""
self._smappee.actuator_on(self._location_id, self._switch_id,

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Why do this twice?

self._remoteswitch)
self._smappee.actuator_on(self._location_id, self._switch_id,
self._remoteswitch)
self._state = True

This comment has been minimized.

Copy link
@balloob

balloob Feb 18, 2018

Member

Why are you setting state to True? You can only do that if you check the command result and make sure the command was successful.

Also, Home Assistant calls your update method after calling a service, which will also query your device

This comment has been minimized.

Copy link
@hmn

hmn Feb 18, 2018

Author Contributor

The plugs don't have any way of communicating with the rest of the smappee system, they work by just sending a signal out and then hoping it is received.

It's not really very nice so setting the state seemed to be the only way I could handle them, if theres a better way to handle switches where you can't get the status just point me in that direction and I'll look into it

@balloob

This comment has been minimized.

Copy link
Member

commented Feb 18, 2018

Please include a link to the docs PR.

@hmn

This comment has been minimized.

Copy link
Contributor Author

commented Feb 18, 2018

update smappee module with reviewer comments
- update smappy module
- cache cloud api requests
- added actuator info
- updated return states
@hmn

This comment has been minimized.

Copy link
Contributor Author

commented Feb 18, 2018

Thanks for al of the feedback, I tried fixing all of it, but I'm not exactly a python expert, so I hope it's better :)

@balloob balloob removed the docs-missing label Feb 18, 2018

@balloob balloob merged commit 72fa170 into home-assistant:dev Feb 18, 2018

5 checks passed

WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls First build on dev at 94.023%
Details
hound No violations found. Woof!
@balloob

This comment has been minimized.

Copy link
Member

commented Feb 18, 2018

Awesome work! 🎉

dmulcahey added a commit to dmulcahey/home-assistant that referenced this pull request Feb 19, 2018

added smappee component (home-assistant#11491)
* added smappee component

* Fixed pylint errors and a few use cases when starting up with invalid credentials

Added coverage omit

* Added support to run only locally
Added a few more sensors
Added more error handling

Better parsing and debug message

* fixed smappee switch after local/remote support was added

* Smappee - update switches for local support (home-assistant#3)

* Merged with local version

* Updated smappy library with the patched one

Fixed lint, added merge missing param

Fixed missing run for requirements_all.txt

Fixed lint

* Fixed on/off based on library. Reverted change used for testing stacktrace

* Fixed switches to work with both remote and local active

Fixed lint

Fixed switches

Fixed lint

* nothing to update per switch as the states are not saved by smappee system

* added better error handling for communication errors with smappee

* fixed lint errors

* fixed comment

* fixed lint error

* fixed lint error

* update smappee module with reviewer comments
- update smappy module
- cache cloud api requests
- added actuator info
- updated return states

@balloob balloob referenced this pull request Feb 22, 2018

Merged

0.64.0 #12609

@hmn hmn deleted the hmn:smappee branch Feb 26, 2018

@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.