Add availability and next run datetime to RainMachine switches (#21786)
This commit is contained in:
parent
18daee9af6
commit
897862fca4
4 changed files with 25 additions and 22 deletions
|
@ -19,7 +19,7 @@ from .config_flow import configured_instances
|
||||||
from .const import (
|
from .const import (
|
||||||
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN)
|
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN)
|
||||||
|
|
||||||
REQUIREMENTS = ['regenmaschine==1.2.0']
|
REQUIREMENTS = ['regenmaschine==1.4.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/switch.rainmachine/
|
https://home-assistant.io/components/switch.rainmachine/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from homeassistant.components.rainmachine import (
|
from homeassistant.components.rainmachine import (
|
||||||
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN, PROGRAM_UPDATE_TOPIC,
|
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN, PROGRAM_UPDATE_TOPIC,
|
||||||
|
@ -19,6 +20,7 @@ DEPENDENCIES = ['rainmachine']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ATTR_NEXT_RUN = 'next_run'
|
||||||
ATTR_AREA = 'area'
|
ATTR_AREA = 'area'
|
||||||
ATTR_CS_ON = 'cs_on'
|
ATTR_CS_ON = 'cs_on'
|
||||||
ATTR_CURRENT_CYCLE = 'current_cycle'
|
ATTR_CURRENT_CYCLE = 'current_cycle'
|
||||||
|
@ -111,20 +113,12 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
programs = await rainmachine.client.programs.all()
|
programs = await rainmachine.client.programs.all(include_inactive=True)
|
||||||
for program in programs:
|
for program in programs:
|
||||||
if not program.get('active'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
_LOGGER.debug('Adding program: %s', program)
|
|
||||||
entities.append(RainMachineProgram(rainmachine, 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:
|
for zone in zones:
|
||||||
if not zone.get('active'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
_LOGGER.debug('Adding zone: %s', zone)
|
|
||||||
entities.append(
|
entities.append(
|
||||||
RainMachineZone(
|
RainMachineZone(
|
||||||
rainmachine, zone, rainmachine.default_zone_runtime))
|
rainmachine, zone, rainmachine.default_zone_runtime))
|
||||||
|
@ -144,16 +138,16 @@ class RainMachineSwitch(RainMachineEntity, SwitchDevice):
|
||||||
self._rainmachine_entity_id = obj['uid']
|
self._rainmachine_entity_id = obj['uid']
|
||||||
self._switch_type = switch_type
|
self._switch_type = switch_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return bool(self._obj.get('active'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self) -> str:
|
def icon(self) -> str:
|
||||||
"""Return the icon."""
|
"""Return the icon."""
|
||||||
return 'mdi:water'
|
return 'mdi:water'
|
||||||
|
|
||||||
@property
|
|
||||||
def is_enabled(self) -> bool:
|
|
||||||
"""Return whether the entity is enabled."""
|
|
||||||
return self._obj.get('active')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique, HASS-friendly identifier for this entity."""
|
"""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._obj = await self.rainmachine.client.programs.get(
|
||||||
self._rainmachine_entity_id)
|
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({
|
self._attrs.update({
|
||||||
ATTR_ID: self._obj['uid'],
|
ATTR_ID: self._obj['uid'],
|
||||||
|
ATTR_NEXT_RUN: next_run,
|
||||||
ATTR_SOAK: self._obj.get('soak'),
|
ATTR_SOAK: self._obj.get('soak'),
|
||||||
ATTR_STATUS: PROGRAM_STATUS_MAP[self._obj.get('status')],
|
ATTR_STATUS: PROGRAM_STATUS_MAP[self._obj.get('status')],
|
||||||
ATTR_ZONES: ', '.join(z['name'] for z in self.zones)
|
ATTR_ZONES: ', '.join(z['name'] for z in self.zones)
|
||||||
|
@ -297,13 +300,13 @@ class RainMachineZone(RainMachineSwitch):
|
||||||
ATTR_CURRENT_CYCLE:
|
ATTR_CURRENT_CYCLE:
|
||||||
self._obj.get('cycle'),
|
self._obj.get('cycle'),
|
||||||
ATTR_FIELD_CAPACITY:
|
ATTR_FIELD_CAPACITY:
|
||||||
self._properties_json.get('waterSense')
|
self._properties_json.get('waterSense').get(
|
||||||
.get('fieldCapacity'),
|
'fieldCapacity'),
|
||||||
ATTR_NO_CYCLES:
|
ATTR_NO_CYCLES:
|
||||||
self._obj.get('noOfCycles'),
|
self._obj.get('noOfCycles'),
|
||||||
ATTR_PRECIP_RATE:
|
ATTR_PRECIP_RATE:
|
||||||
self._properties_json.get('waterSense')
|
self._properties_json.get('waterSense').get(
|
||||||
.get('precipitationRate'),
|
'precipitationRate'),
|
||||||
ATTR_RESTRICTIONS:
|
ATTR_RESTRICTIONS:
|
||||||
self._obj.get('restriction'),
|
self._obj.get('restriction'),
|
||||||
ATTR_SLOPE:
|
ATTR_SLOPE:
|
||||||
|
|
|
@ -1505,7 +1505,7 @@ raspyrfm-client==1.2.8
|
||||||
recollect-waste==1.0.1
|
recollect-waste==1.0.1
|
||||||
|
|
||||||
# homeassistant.components.rainmachine
|
# homeassistant.components.rainmachine
|
||||||
regenmaschine==1.2.0
|
regenmaschine==1.4.0
|
||||||
|
|
||||||
# homeassistant.components.python_script
|
# homeassistant.components.python_script
|
||||||
restrictedpython==4.0b8
|
restrictedpython==4.0b8
|
||||||
|
|
|
@ -261,7 +261,7 @@ pyunifi==2.16
|
||||||
pywebpush==1.6.0
|
pywebpush==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.rainmachine
|
# homeassistant.components.rainmachine
|
||||||
regenmaschine==1.2.0
|
regenmaschine==1.4.0
|
||||||
|
|
||||||
# homeassistant.components.python_script
|
# homeassistant.components.python_script
|
||||||
restrictedpython==4.0b8
|
restrictedpython==4.0b8
|
||||||
|
|
Loading…
Add table
Reference in a new issue