Skip to content

Add juicenet platform#7668

Merged
balloob merged 12 commits into
home-assistant:devfrom
jesserockz:juicenet-platform
Jun 5, 2017
Merged

Add juicenet platform#7668
balloob merged 12 commits into
home-assistant:devfrom
jesserockz:juicenet-platform

Conversation

@jesserockz
Copy link
Copy Markdown
Member

@jesserockz jesserockz commented May 20, 2017

Description:

The juicenet sensor platform pulls data from a JuiceNet Charging station equipped with a wifi connection.

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

Example entry for configuration.yaml (if applicable):

juicenet:
    access_token: ACCESS_TOKEN

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.

@mention-bot
Copy link
Copy Markdown

@jesserockz, 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.

attributes = super().device_state_attributes
if self.type == 'status':
if man_dev_id:
attributes["manufacturer_device_id"] = man_dev_id
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'man_dev_id'

"""Return the state attributes."""
attributes = super().device_state_attributes
if self.type == 'status':
if man_dev_id:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'man_dev_id'

'energy_added': ['Energy added', 'Wh']
}

def setup_platform(hass, config, add_devices, discovery_info=None):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1


return True

class JuicenetDevice(Entity):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

})
}, extra=vol.ALLOW_EXTRA)

def setup(hass, config):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

Add missing blank lines

class JuicenetSensorDevice(JuicenetDevice, Entity):
"""Implementation of a Juicenet sensor."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace

Add missing docstring
Comment thread homeassistant/components/juicenet.py Outdated
_LOGGER.info("Refreshing Juicenet states from API")
for entity_list in hass[DOMAIN]['entities'].values():
for entity in entity_list:
time.sleep(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't use sleep. Can you fetch all the data at once and then notifiy the entities with new info?

Comment thread homeassistant/components/juicenet.py Outdated
def pull_new_devices(call):
"""Pull new devices added to users Juicenet account since startup."""
_LOGGER.info("Getting new devices from Juicenet API")
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a very weird way of "pulling" new devices. Why can't you talk to the API directly?

dev = []
for device in api.get_devices():
_id = device.id()
if _id not in hass.data[DOMAIN]['unique_ids']:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't have to do this, Home Assistant does this automatically as long as you implement the property unique_id.

Use the hass built in unique_id
for device in api.get_devices():
_id = device.id()
for variable in SENSOR_TYPES:
if "{}-{}".format(_id, variable) not in hass.data[DOMAIN]['unique_ids']:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (84 > 79 characters)

Comment thread homeassistant/components/juicenet.py Outdated
"""

import logging
import time
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'time' imported but unused

@asyncio.coroutine
def async_added_to_hass(self):
"""Callback when entity is added to hass."""
self.hass.data[DOMAIN]['entities']['sensor'].append(self)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are you appending it, is this still necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above

for device in api.get_devices():
for variable in SENSOR_TYPES:
_id = "{}-{}".format(device.id(), variable)
if _id not in hass.data[DOMAIN]['unique_ids']:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check is no longer necessary

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, I was writing this integration while looking at the wink one.

elif self.type == 'energy_added':
icon = 'mdi:flash'
else:
icon = 'mdi:eye'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should return None. That will cause Home Assistant to use the default sensor icon.

Comment thread homeassistant/components/juicenet.py Outdated
def device_state_attributes(self):
"""Return the state attributes."""
attributes = {}
if self.type == 'status':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't be in a generic JuiceNet entity. This is part of an implementation.

Comment thread homeassistant/components/juicenet.py Outdated

hass.data[DOMAIN] = {}
hass.data[DOMAIN]['unique_ids'] = []
hass.data[DOMAIN]['entities'] = {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're no longer using this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above

@jesserockz
Copy link
Copy Markdown
Member Author

Thanks for the feedback @balloob, Im guessing homeassistant has evolved a bit since the wink platform was written.

at https://home-assistant.io/components/sensor.juicenet/
"""

import asyncio
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'asyncio' imported but unused

@jesserockz
Copy link
Copy Markdown
Member Author

@balloob It looks like a previous PR merge has broken the lint test #7318
code link

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Looks great 🐬 👍 Thanks!

@balloob balloob merged commit aee25a0 into home-assistant:dev Jun 5, 2017
@balloob balloob mentioned this pull request Jun 16, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
@jesserockz jesserockz deleted the juicenet-platform branch February 8, 2018 04:16
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