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

LaMetric platform and notify module #8230

Merged
merged 17 commits into from Jul 7, 2017

Conversation

Projects
None yet
8 participants
@open-homeautomation
Copy link
Contributor

commented Jun 28, 2017

Description:

This adds a platform module for LaMetric time (http://lametric.com/)
Right now only notify is supported to send local notifications. However more features (e.g. media player functionality can be implemented on this platform).

There are options to use specific icons and send the notifications only a subset of LaMetric devices.

This is an request-for-comments: let me know if something should be implemented differently.

Notify examples:
{ "message" : "Test” }
{ "message" : "Test" , "data": { "icon" : "i555"} }
{ "message" : "Test" , "data": { "icon" : "i555"}, "target": ["My Lametric"] }

Related issue (if applicable):

Pull request in home-assistant.github.io with documentation (if applicable):
Not yet done. I will create this, if the module and configuration are accepted and stable

Example entry for configuration.yaml (if applicable):

lametric:
  client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
  client_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

notify:
  name: lametric1
  platform: lametric
  display_time: 20
  icon: i555

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.
@mention-bot

This comment has been minimized.

Copy link

commented Jun 28, 2017

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

sound_id=data["sound"])
_LOGGER.debug("Adding notification sound %s",
data["sound"])
frames.append(sound)

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

undefined name 'frames'

config[CONF_DISPLAY_TIME] * 1000)
except HomeAssistantError:
_LOGGER.exception("Could not configure LaMetric device %s",
config[CONF_DEVICENAME])

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

undefined name 'CONF_DEVICENAME'

"""
A class that encapsulated requests to the LaMetric manager.
Implements a singleton pattern. Also monitors for "token" expired

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

trailing whitespace

_LOGGER.debug("Setting up LaMetric platform")
try:
lmn = HassLaMetricManager(client_id=config[DOMAIN][CONF_CLIENT_ID],
client_secret=config[DOMAIN][CONF_CLIENT_SECRET])

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

line too long (83 > 79 characters)

def setup(hass, config):
"""Set up the LaMetricManager."""

from lmnotify import LaMetricManager

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

'lmnotify.LaMetricManager' imported but unused

"""
Support for LaMetric time.
This is the base platform to support LaMetric components:

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 28, 2017

trailing whitespace

open-homeautomation added some commits Jun 28, 2017

return found


class HassLaMetricManager():

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jun 29, 2017

Member

Please change the class designe to a instancable class that is stored in hass.data. This class is like global what is not allow anymore.

This comment has been minimized.

Copy link
@open-homeautomation

open-homeautomation Jun 29, 2017

Author Contributor

This has been changed how. The global instance is stored in hass.data now.

from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv

from homeassistant.components.lametric import DOMAIN, HassLaMetricManager

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jun 29, 2017

'homeassistant.components.lametric.HassLaMetricManager' imported but unused

_LOGGER.debug("Connecting to LaMetric")
HassLaMetricManager.lmn = LaMetricManager(client_id, client_secret)
HassLaMetricManager._client_id = client_id
HassLaMetricManager._client_secret = client_secret

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jun 29, 2017

Member

use self

_LOGGER.debug("Reconnecting to LaMetric")
HassLaMetricManager.lmn = \
LaMetricManager(self._client_id,
self._client_secret)

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jun 29, 2017

Member

use self

open-homeautomation added some commits Jun 29, 2017

hlmn = HassLaMetricManager(client_id=conf[CONF_CLIENT_ID],
client_secret=conf[CONF_CLIENT_SECRET])
devices = hlmn.manager().get_devices()
except Exception as exception:

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

Broad-except is bad and we catch it on core. Please set the specific exception

This comment has been minimized.

Copy link
@open-homeautomation

open-homeautomation Jul 3, 2017

Author Contributor

The possible exceptions aren't documented. I've already seen oauth exceptions, but there can be all kind of other exceptions.
I can remove the except completely. Personally I don't think this is a better solution.

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

You can start with oauth and add more if you see others or other user report one

return LaMetricNotificationService(hlmn,
config[CONF_ICON],
config[CONF_DISPLAY_TIME] * 1000)
except HomeAssistantError:

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

Are you sure that will be possible?

This comment has been minimized.

Copy link
@open-homeautomation

open-homeautomation Jul 3, 2017

Author Contributor

Ok, this seems to be some old code. I can remove this.

sound_id=data["sound"])
_LOGGER.debug("Adding notification sound %s",
data["sound"])
except Exception:

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

Specifiy exception

This comment has been minimized.

Copy link
@open-homeautomation

open-homeautomation Jul 3, 2017

Author Contributor

The possible exceptions aren't documented. I've already seen oauth exceptions, but there can be all kind of other exceptions.
I can remove the except completely. Personally I don't think this is a better solution.

hass.data[LAMETRIC_DEVICES] = []
for dev in devices:
_LOGGER.debug("Discovered LaMetric device: %s", dev)
hass.data[LAMETRIC_DEVICES].append(dev)

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

Why do you store that? Please remove it.

This comment has been minimized.

Copy link
@open-homeautomation

open-homeautomation Jul 3, 2017

Author Contributor

This might become handy to have this ready for other devices based on the platform. But I can remove it for now.

This comment has been minimized.

Copy link
@pvizeli

pvizeli Jul 3, 2017

Member

Yeah we can add this if we had a use case for it.

open-homeautomation added some commits Jul 6, 2017

Removed broad excepts
Removed storage of LaMetric devices
from homeassistant.components.notify import (
ATTR_TARGET, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import CONF_ICON
from homeassistant.exceptions import HomeAssistantError

This comment has been minimized.

Copy link
@houndci-bot

houndci-bot Jul 6, 2017

'homeassistant.exceptions.HomeAssistantError' imported but unused

@pvizeli

pvizeli approved these changes Jul 7, 2017

Copy link
Member

left a comment

Leave a comment

@pvizeli pvizeli merged commit 7536e82 into home-assistant:dev Jul 7, 2017

4 checks passed

cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 93.594%
Details
hound No violations found. Woof!
@heytcass

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2017

Very excited someone tackled this. I gave an attempt a bit back, but wasn't able to make it work, so kudos.

As part of my attempt, I did make a Home Assistant icon on the LaMetric developer site. It is #3579, and looks like this.

3579_icon_thumb_lg

If you want to use it at all, feel free. 👍

@balloob balloob referenced this pull request Jul 13, 2017

Merged

0.49 #8468

@balloob

This comment has been minimized.

Copy link
Member

commented Jul 16, 2017

Documentation has never been submitted 😢

@open-homeautomation

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2017

I will do that.

dethpickle added a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017

LaMetric platform and notify module (home-assistant#8230)
* First version of a LaMetrci platform with a Notify module

* Cleanup, fix formatting bugs

* More formatting

* Formatting

* Updated requirements

* formatting

* Formatting

* More formatting

* Dummy commit for new Travis CI run

* Refactoring class methods to instance methods

* Cleanup unused classed

* Removed Eddystone_weatherurl that had nothing to do with this component

* Cleanup class methods

* Cleanup requirements

* Removed broad excepts
Removed storage of LaMetric devices

* Removed unused import

@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017

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.