Add juicenet platform#7668
Conversation
|
@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 |
| """Return the state attributes.""" | ||
| attributes = super().device_state_attributes | ||
| if self.type == 'status': | ||
| if man_dev_id: |
| 'energy_added': ['Energy added', 'Wh'] | ||
| } | ||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): |
|
|
||
| return True | ||
|
|
||
| class JuicenetDevice(Entity): |
| }) | ||
| }, extra=vol.ALLOW_EXTRA) | ||
|
|
||
| def setup(hass, config): |
Add missing blank lines
|
|
||
| class JuicenetSensorDevice(JuicenetDevice, Entity): | ||
| """Implementation of a Juicenet sensor.""" | ||
|
|
Add missing docstring
| _LOGGER.info("Refreshing Juicenet states from API") | ||
| for entity_list in hass[DOMAIN]['entities'].values(): | ||
| for entity in entity_list: | ||
| time.sleep(1) |
There was a problem hiding this comment.
Please don't use sleep. Can you fetch all the data at once and then notifiy the entities with new info?
| 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) |
There was a problem hiding this comment.
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']: |
There was a problem hiding this comment.
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']: |
There was a problem hiding this comment.
line too long (84 > 79 characters)
| """ | ||
|
|
||
| import logging | ||
| import time |
| @asyncio.coroutine | ||
| def async_added_to_hass(self): | ||
| """Callback when entity is added to hass.""" | ||
| self.hass.data[DOMAIN]['entities']['sensor'].append(self) |
There was a problem hiding this comment.
Why are you appending it, is this still necessary?
| 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']: |
There was a problem hiding this comment.
This check is no longer necessary
There was a problem hiding this comment.
Thanks, I was writing this integration while looking at the wink one.
| elif self.type == 'energy_added': | ||
| icon = 'mdi:flash' | ||
| else: | ||
| icon = 'mdi:eye' |
There was a problem hiding this comment.
You should return None. That will cause Home Assistant to use the default sensor icon.
| def device_state_attributes(self): | ||
| """Return the state attributes.""" | ||
| attributes = {} | ||
| if self.type == 'status': |
There was a problem hiding this comment.
This shouldn't be in a generic JuiceNet entity. This is part of an implementation.
|
|
||
| hass.data[DOMAIN] = {} | ||
| hass.data[DOMAIN]['unique_ids'] = [] | ||
| hass.data[DOMAIN]['entities'] = {} |
|
Thanks for the feedback @balloob, Im guessing |
| at https://home-assistant.io/components/sensor.juicenet/ | ||
| """ | ||
|
|
||
| import asyncio |
Description:
The
juicenetsensor 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):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.