Add availability and next run datetime to RainMachine switches (#21786)

This commit is contained in:
Aaron Bach 2019-03-13 08:19:26 -06:00 committed by GitHub
parent 18daee9af6
commit 897862fca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 22 deletions

View file

@ -19,7 +19,7 @@ from .config_flow import configured_instances
from .const import (
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN)
REQUIREMENTS = ['regenmaschine==1.2.0']
REQUIREMENTS = ['regenmaschine==1.4.0']
_LOGGER = logging.getLogger(__name__)

View file

@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/switch.rainmachine/
"""
import logging
from datetime import datetime
from homeassistant.components.rainmachine import (
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN, PROGRAM_UPDATE_TOPIC,
@ -19,6 +20,7 @@ DEPENDENCIES = ['rainmachine']
_LOGGER = logging.getLogger(__name__)
ATTR_NEXT_RUN = 'next_run'
ATTR_AREA = 'area'
ATTR_CS_ON = 'cs_on'
ATTR_CURRENT_CYCLE = 'current_cycle'
@ -111,20 +113,12 @@ async def async_setup_entry(hass, entry, async_add_entities):
entities = []
programs = await rainmachine.client.programs.all()
programs = await rainmachine.client.programs.all(include_inactive=True)
for program in programs:
if not program.get('active'):
continue
_LOGGER.debug('Adding program: %s', program)
entities.append(RainMachineProgram(rainmachine, program))
zones = await rainmachine.client.zones.all()
zones = await rainmachine.client.zones.all(include_inactive=True)
for zone in zones:
if not zone.get('active'):
continue
_LOGGER.debug('Adding zone: %s', zone)
entities.append(
RainMachineZone(
rainmachine, zone, rainmachine.default_zone_runtime))
@ -144,16 +138,16 @@ class RainMachineSwitch(RainMachineEntity, SwitchDevice):
self._rainmachine_entity_id = obj['uid']
self._switch_type = switch_type
@property
def available(self) -> bool:
"""Return True if entity is available."""
return bool(self._obj.get('active'))
@property
def icon(self) -> str:
"""Return the icon."""
return 'mdi:water'
@property
def is_enabled(self) -> bool:
"""Return whether the entity is enabled."""
return self._obj.get('active')
@property
def unique_id(self) -> str:
"""Return a unique, HASS-friendly identifier for this entity."""
@ -222,8 +216,17 @@ class RainMachineProgram(RainMachineSwitch):
self._obj = await self.rainmachine.client.programs.get(
self._rainmachine_entity_id)
try:
next_run = datetime.strptime(
'{0} {1}'.format(
self._obj['nextRun'], self._obj['startTime']),
'%Y-%m-%d %H:%M').isoformat()
except ValueError:
next_run = None
self._attrs.update({
ATTR_ID: self._obj['uid'],
ATTR_NEXT_RUN: next_run,
ATTR_SOAK: self._obj.get('soak'),
ATTR_STATUS: PROGRAM_STATUS_MAP[self._obj.get('status')],
ATTR_ZONES: ', '.join(z['name'] for z in self.zones)
@ -297,13 +300,13 @@ class RainMachineZone(RainMachineSwitch):
ATTR_CURRENT_CYCLE:
self._obj.get('cycle'),
ATTR_FIELD_CAPACITY:
self._properties_json.get('waterSense')
.get('fieldCapacity'),
self._properties_json.get('waterSense').get(
'fieldCapacity'),
ATTR_NO_CYCLES:
self._obj.get('noOfCycles'),
ATTR_PRECIP_RATE:
self._properties_json.get('waterSense')
.get('precipitationRate'),
self._properties_json.get('waterSense').get(
'precipitationRate'),
ATTR_RESTRICTIONS:
self._obj.get('restriction'),
ATTR_SLOPE:

View file

@ -1505,7 +1505,7 @@ raspyrfm-client==1.2.8
recollect-waste==1.0.1
# homeassistant.components.rainmachine
regenmaschine==1.2.0
regenmaschine==1.4.0
# homeassistant.components.python_script
restrictedpython==4.0b8

View file

@ -261,7 +261,7 @@ pyunifi==2.16
pywebpush==1.6.0
# homeassistant.components.rainmachine
regenmaschine==1.2.0
regenmaschine==1.4.0
# homeassistant.components.python_script
restrictedpython==4.0b8