Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions homeassistant/components/rainmachine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for RainMachine devices."""
import asyncio
import logging
from datetime import timedelta
from functools import wraps
Expand All @@ -20,7 +21,8 @@

from .config_flow import configured_instances
from .const import (
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN)
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN,
OPERATION_RESTRICTIONS_CURRENT, OPERATION_RESTRICTIONS_UNIVERSAL)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -346,17 +348,30 @@ def __init__(
"""Initialize."""
self.binary_sensor_conditions = binary_sensor_conditions
self.client = client
self.data = {}
self.default_zone_runtime = default_zone_runtime
self.device_mac = self.client.mac
self.restrictions = {}
self.sensor_conditions = sensor_conditions

async def async_update(self):
"""Update sensor/binary sensor data."""
self.restrictions.update({
'current': await self.client.restrictions.current(),
'global': await self.client.restrictions.universal()
})
from regenmaschine.errors import RainMachineError

tasks = {
OPERATION_RESTRICTIONS_CURRENT: self.client.restrictions.current(),
OPERATION_RESTRICTIONS_UNIVERSAL:
self.client.restrictions.universal(),
}

results = await asyncio.gather(*tasks.values(), return_exceptions=True)
for operation, result in zip(tasks, results):
if isinstance(result, RainMachineError):
_LOGGER.error(
'There was an error while updating %s: %s', operation,
result)
continue

self.data[operation] = result


class RainMachineEntity(Entity):
Expand Down
28 changes: 17 additions & 11 deletions homeassistant/components/rainmachine/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from . import (
BINARY_SENSORS, DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN,
OPERATION_RESTRICTIONS_CURRENT, OPERATION_RESTRICTIONS_UNIVERSAL,
SENSOR_UPDATE_TOPIC, TYPE_FREEZE, TYPE_FREEZE_PROTECTION, TYPE_HOT_DAYS,
TYPE_HOURLY, TYPE_MONTH, TYPE_RAINDELAY, TYPE_RAINSENSOR, TYPE_WEEKDAY,
RainMachineEntity)
Expand Down Expand Up @@ -79,21 +80,26 @@ def update():
async def async_update(self):
"""Update the state."""
if self._sensor_type == TYPE_FREEZE:
self._state = self.rainmachine.restrictions['current']['freeze']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['freeze']
elif self._sensor_type == TYPE_FREEZE_PROTECTION:
self._state = self.rainmachine.restrictions['global'][
'freezeProtectEnabled']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_UNIVERSAL]['freezeProtectEnabled']
elif self._sensor_type == TYPE_HOT_DAYS:
self._state = self.rainmachine.restrictions['global'][
'hotDaysExtraWatering']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_UNIVERSAL]['hotDaysExtraWatering']
elif self._sensor_type == TYPE_HOURLY:
self._state = self.rainmachine.restrictions['current']['hourly']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['hourly']
elif self._sensor_type == TYPE_MONTH:
self._state = self.rainmachine.restrictions['current']['month']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['month']
elif self._sensor_type == TYPE_RAINDELAY:
self._state = self.rainmachine.restrictions['current']['rainDelay']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['rainDelay']
elif self._sensor_type == TYPE_RAINSENSOR:
self._state = self.rainmachine.restrictions['current'][
'rainSensor']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['rainSensor']
elif self._sensor_type == TYPE_WEEKDAY:
self._state = self.rainmachine.restrictions['current']['weekDay']
self._state = self.rainmachine.data[
OPERATION_RESTRICTIONS_CURRENT]['weekDay']
3 changes: 3 additions & 0 deletions homeassistant/components/rainmachine/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
DEFAULT_SCAN_INTERVAL = timedelta(seconds=60)
DEFAULT_SSL = True

OPERATION_RESTRICTIONS_CURRENT = 'restrictions.current'
OPERATION_RESTRICTIONS_UNIVERSAL = 'restrictions.universal'

TOPIC_UPDATE = 'update_{0}'
5 changes: 3 additions & 2 deletions homeassistant/components/rainmachine/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect

from . import (
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN, SENSOR_UPDATE_TOPIC, SENSORS,
DATA_CLIENT, DOMAIN as RAINMACHINE_DOMAIN,
OPERATION_RESTRICTIONS_UNIVERSAL, SENSOR_UPDATE_TOPIC, SENSORS,
RainMachineEntity)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -81,5 +82,5 @@ def update():

async def async_update(self):
"""Update the sensor's state."""
self._state = self.rainmachine.restrictions['global'][
self._state = self.rainmachine.data[OPERATION_RESTRICTIONS_UNIVERSAL][
'freezeProtectTemp']