commit
779188ad27
3 changed files with 31 additions and 8 deletions
|
@ -14,14 +14,24 @@ from homeassistant.components.sensor import DOMAIN
|
|||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers import validate_config
|
||||
|
||||
REQUIREMENTS = ['mficlient==0.2']
|
||||
REQUIREMENTS = ['mficlient==0.2.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STATE_ON = 'on'
|
||||
STATE_OFF = 'off'
|
||||
DIGITS = {
|
||||
'volts': 1,
|
||||
'amps': 1,
|
||||
'active_power': 0,
|
||||
'temperature': 1,
|
||||
}
|
||||
SENSOR_MODELS = [
|
||||
'Ubiquiti mFi-THS',
|
||||
'Ubiquiti mFi-CS',
|
||||
'Outlet',
|
||||
'Input Analog',
|
||||
'Input Digital',
|
||||
]
|
||||
|
||||
|
||||
|
@ -69,7 +79,11 @@ class MfiSensor(Entity):
|
|||
|
||||
@property
|
||||
def state(self):
|
||||
return self._port.value
|
||||
if self._port.model == 'Input Digital':
|
||||
return self._port.value > 0 and STATE_ON or STATE_OFF
|
||||
else:
|
||||
digits = DIGITS.get(self._port.tag, 0)
|
||||
return round(self._port.value, digits)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
@ -77,6 +91,8 @@ class MfiSensor(Entity):
|
|||
return TEMP_CELCIUS
|
||||
elif self._port.tag == 'active_pwr':
|
||||
return 'Watts'
|
||||
elif self._port.model == 'Input Digital':
|
||||
return 'State'
|
||||
return self._port.tag
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -12,12 +12,15 @@ from homeassistant.components.switch import DOMAIN, SwitchDevice
|
|||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
||||
from homeassistant.helpers import validate_config
|
||||
|
||||
REQUIREMENTS = ['mficlient==0.2']
|
||||
REQUIREMENTS = ['mficlient==0.2.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SWITCH_MODELS = [
|
||||
'Outlet',
|
||||
'Output 5v',
|
||||
'Output 12v',
|
||||
'Output 24v',
|
||||
]
|
||||
|
||||
|
||||
|
@ -56,6 +59,7 @@ class MfiSwitch(SwitchDevice):
|
|||
""" An mFi switch-able device. """
|
||||
def __init__(self, port):
|
||||
self._port = port
|
||||
self._target_state = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -75,14 +79,17 @@ class MfiSwitch(SwitchDevice):
|
|||
|
||||
def update(self):
|
||||
self._port.refresh()
|
||||
if self._target_state is not None:
|
||||
self._port.data['output'] = float(self._target_state)
|
||||
self._target_state = None
|
||||
|
||||
def turn_on(self):
|
||||
self._port.control(True)
|
||||
self._port.data['output'] = 1.0
|
||||
self._target_state = True
|
||||
|
||||
def turn_off(self):
|
||||
self._port.control(False)
|
||||
self._port.data['output'] = 0.0
|
||||
self._target_state = False
|
||||
|
||||
@property
|
||||
def current_power_mwh(self):
|
||||
|
@ -91,6 +98,6 @@ class MfiSwitch(SwitchDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
attr = {}
|
||||
attr['volts'] = self._port.data.get('v_rms', 0)
|
||||
attr['amps'] = self._port.data.get('i_rms', 0)
|
||||
attr['volts'] = round(self._port.data.get('v_rms', 0), 1)
|
||||
attr['amps'] = round(self._port.data.get('i_rms', 0), 1)
|
||||
return attr
|
||||
|
|
|
@ -107,7 +107,7 @@ limitlessled==1.0.0
|
|||
|
||||
# homeassistant.components.sensor.mfi
|
||||
# homeassistant.components.switch.mfi
|
||||
mficlient==0.2
|
||||
mficlient==0.2.2
|
||||
|
||||
# homeassistant.components.discovery
|
||||
netdisco==0.5.2
|
||||
|
|
Loading…
Add table
Reference in a new issue