Add juicenet platform (#7668)
* Add juicenet platform * Update missing variable Add missing blank lines * Remove unnecessary override * Update juicenet.py * Remove whitespace Add missing docstring * Remove unused services Use the hass built in unique_id * Fix lint issues * Update python-juicenet library version * Update python-juicenet library version * Remove unnecessary code * Remove unused import * Remove super call
This commit is contained in:
parent
13df925795
commit
aee25a020d
4 changed files with 195 additions and 0 deletions
|
@ -65,6 +65,9 @@ omit =
|
|||
homeassistant/components/isy994.py
|
||||
homeassistant/components/*/isy994.py
|
||||
|
||||
homeassistant/components/juicenet.py
|
||||
homeassistant/components/*/juicenet.py
|
||||
|
||||
homeassistant/components/kira.py
|
||||
homeassistant/components/*/kira.py
|
||||
|
||||
|
|
74
homeassistant/components/juicenet.py
Normal file
74
homeassistant/components/juicenet.py
Normal file
|
@ -0,0 +1,74 @@
|
|||
"""
|
||||
Support for Juicenet cloud.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/juicenet
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['python-juicenet==0.0.5']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'juicenet'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_ACCESS_TOKEN): cv.string
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Juicenet component."""
|
||||
import pyjuicenet
|
||||
|
||||
hass.data[DOMAIN] = {}
|
||||
|
||||
access_token = config[DOMAIN].get(CONF_ACCESS_TOKEN)
|
||||
hass.data[DOMAIN]['api'] = pyjuicenet.Api(access_token)
|
||||
|
||||
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
|
||||
return True
|
||||
|
||||
|
||||
class JuicenetDevice(Entity):
|
||||
"""Represent a base Juicenet device."""
|
||||
|
||||
def __init__(self, device, sensor_type, hass):
|
||||
"""Initialise the sensor."""
|
||||
self.hass = hass
|
||||
self.device = device
|
||||
self.type = sensor_type
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self.device.name()
|
||||
|
||||
def update(self):
|
||||
"""Update state of the device."""
|
||||
self.device.update_state()
|
||||
|
||||
@property
|
||||
def _manufacturer_device_id(self):
|
||||
"""Return the manufacturer device id."""
|
||||
return self.device.id()
|
||||
|
||||
@property
|
||||
def _token(self):
|
||||
"""Return the device API token."""
|
||||
return self.device.token()
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return an unique ID."""
|
||||
return "{}-{}".format(self.device.id(), self.type)
|
115
homeassistant/components/sensor/juicenet.py
Normal file
115
homeassistant/components/sensor/juicenet.py
Normal file
|
@ -0,0 +1,115 @@
|
|||
"""
|
||||
Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
at https://home-assistant.io/components/sensor.juicenet/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.juicenet import JuicenetDevice, DOMAIN
|
||||
|
||||
DEPENDENCIES = ['juicenet']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
'status': ['Charging Status', None],
|
||||
'temperature': ['Temperature', TEMP_CELSIUS],
|
||||
'voltage': ['Voltage', 'V'],
|
||||
'amps': ['Amps', 'A'],
|
||||
'watts': ['Watts', 'W'],
|
||||
'charge_time': ['Charge time', 's'],
|
||||
'energy_added': ['Energy added', 'Wh']
|
||||
}
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Juicenet sensor."""
|
||||
api = hass.data[DOMAIN]['api']
|
||||
|
||||
dev = []
|
||||
for device in api.get_devices():
|
||||
for variable in SENSOR_TYPES:
|
||||
dev.append(JuicenetSensorDevice(device, variable, hass))
|
||||
|
||||
add_devices(dev)
|
||||
|
||||
|
||||
class JuicenetSensorDevice(JuicenetDevice, Entity):
|
||||
"""Implementation of a Juicenet sensor."""
|
||||
|
||||
def __init__(self, device, sensor_type, hass):
|
||||
"""Initialise the sensor."""
|
||||
super().__init__(device, sensor_type, hass)
|
||||
self._name = SENSOR_TYPES[sensor_type][0]
|
||||
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return '{} {}'.format(self.device.name(), self._name)
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon of the sensor."""
|
||||
icon = None
|
||||
if self.type == 'status':
|
||||
status = self.device.getStatus()
|
||||
if status == 'standby':
|
||||
icon = 'mdi:power-plug-off'
|
||||
elif status == 'plugged':
|
||||
icon = 'mdi:power-plug'
|
||||
elif status == 'charging':
|
||||
icon = 'mdi:battery-positive'
|
||||
elif self.type == 'temperature':
|
||||
icon = 'mdi:thermometer'
|
||||
elif self.type == 'voltage':
|
||||
icon = 'mdi:flash'
|
||||
elif self.type == 'amps':
|
||||
icon = 'mdi:flash'
|
||||
elif self.type == 'watts':
|
||||
icon = 'mdi:flash'
|
||||
elif self.type == 'charge_time':
|
||||
icon = 'mdi:timer'
|
||||
elif self.type == 'energy_added':
|
||||
icon = 'mdi:flash'
|
||||
return icon
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state."""
|
||||
state = None
|
||||
if self.type == 'status':
|
||||
state = self.device.getStatus()
|
||||
elif self.type == 'temperature':
|
||||
state = self.device.getTemperature()
|
||||
elif self.type == 'voltage':
|
||||
state = self.device.getVoltage()
|
||||
elif self.type == 'amps':
|
||||
state = self.device.getAmps()
|
||||
elif self.type == 'watts':
|
||||
state = self.device.getWatts()
|
||||
elif self.type == 'charge_time':
|
||||
state = self.device.getChargeTime()
|
||||
elif self.type == 'energy_added':
|
||||
state = self.device.getEnergyAdded()
|
||||
else:
|
||||
state = 'Unknown'
|
||||
return state
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attributes = {}
|
||||
if self.type == 'status':
|
||||
man_dev_id = self.device.id()
|
||||
if man_dev_id:
|
||||
attributes["manufacturer_device_id"] = man_dev_id
|
||||
return attributes
|
|
@ -676,6 +676,9 @@ python-hpilo==3.9
|
|||
# homeassistant.components.notify.joaoapps_join
|
||||
python-join-api==0.0.2
|
||||
|
||||
# homeassistant.components.juicenet
|
||||
python-juicenet==0.0.5
|
||||
|
||||
# homeassistant.components.lirc
|
||||
# python-lirc==1.2.3
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue