Fix bug with 1st gen RainMachine controllers and unknown API calls (#78070)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Aaron Bach 2022-09-08 14:41:09 -06:00 committed by GitHub
parent 52d2ebd2c8
commit 9fc9d50e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View file

@ -9,7 +9,7 @@ from typing import Any
from regenmaschine import Client from regenmaschine import Client
from regenmaschine.controller import Controller from regenmaschine.controller import Controller
from regenmaschine.errors import RainMachineError from regenmaschine.errors import RainMachineError, UnknownAPICallError
import voluptuous as vol import voluptuous as vol
from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.config_entries import ConfigEntry, ConfigEntryState
@ -190,7 +190,9 @@ async def async_update_programs_and_zones(
) )
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry( # noqa: C901
hass: HomeAssistant, entry: ConfigEntry
) -> bool:
"""Set up RainMachine as config entry.""" """Set up RainMachine as config entry."""
websession = aiohttp_client.async_get_clientsession(hass) websession = aiohttp_client.async_get_clientsession(hass)
client = Client(session=websession) client = Client(session=websession)
@ -244,6 +246,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data = await controller.restrictions.universal() data = await controller.restrictions.universal()
else: else:
data = await controller.zones.all(details=True, include_inactive=True) data = await controller.zones.all(details=True, include_inactive=True)
except UnknownAPICallError:
LOGGER.info(
"Skipping unsupported API call for controller %s: %s",
controller.name,
api_category,
)
except RainMachineError as err: except RainMachineError as err:
raise UpdateFailed(err) from err raise UpdateFailed(err) from err

View file

@ -175,7 +175,9 @@ class ProvisionSettingsBinarySensor(RainMachineEntity, BinarySensorEntity):
def update_from_latest_data(self) -> None: def update_from_latest_data(self) -> None:
"""Update the state.""" """Update the state."""
if self.entity_description.key == TYPE_FLOW_SENSOR: if self.entity_description.key == TYPE_FLOW_SENSOR:
self._attr_is_on = self.coordinator.data["system"].get("useFlowSensor") self._attr_is_on = self.coordinator.data.get("system", {}).get(
"useFlowSensor"
)
class UniversalRestrictionsBinarySensor(RainMachineEntity, BinarySensorEntity): class UniversalRestrictionsBinarySensor(RainMachineEntity, BinarySensorEntity):

View file

@ -3,7 +3,7 @@
"name": "RainMachine", "name": "RainMachine",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/rainmachine", "documentation": "https://www.home-assistant.io/integrations/rainmachine",
"requirements": ["regenmaschine==2022.08.0"], "requirements": ["regenmaschine==2022.09.0"],
"codeowners": ["@bachya"], "codeowners": ["@bachya"],
"iot_class": "local_polling", "iot_class": "local_polling",
"homekit": { "homekit": {

View file

@ -273,12 +273,14 @@ class ProvisionSettingsSensor(RainMachineEntity, SensorEntity):
def update_from_latest_data(self) -> None: def update_from_latest_data(self) -> None:
"""Update the state.""" """Update the state."""
if self.entity_description.key == TYPE_FLOW_SENSOR_CLICK_M3: if self.entity_description.key == TYPE_FLOW_SENSOR_CLICK_M3:
self._attr_native_value = self.coordinator.data["system"].get( self._attr_native_value = self.coordinator.data.get("system", {}).get(
"flowSensorClicksPerCubicMeter" "flowSensorClicksPerCubicMeter"
) )
elif self.entity_description.key == TYPE_FLOW_SENSOR_CONSUMED_LITERS: elif self.entity_description.key == TYPE_FLOW_SENSOR_CONSUMED_LITERS:
clicks = self.coordinator.data["system"].get("flowSensorWateringClicks") clicks = self.coordinator.data.get("system", {}).get(
clicks_per_m3 = self.coordinator.data["system"].get( "flowSensorWateringClicks"
)
clicks_per_m3 = self.coordinator.data.get("system", {}).get(
"flowSensorClicksPerCubicMeter" "flowSensorClicksPerCubicMeter"
) )
@ -287,11 +289,11 @@ class ProvisionSettingsSensor(RainMachineEntity, SensorEntity):
else: else:
self._attr_native_value = None self._attr_native_value = None
elif self.entity_description.key == TYPE_FLOW_SENSOR_START_INDEX: elif self.entity_description.key == TYPE_FLOW_SENSOR_START_INDEX:
self._attr_native_value = self.coordinator.data["system"].get( self._attr_native_value = self.coordinator.data.get("system", {}).get(
"flowSensorStartIndex" "flowSensorStartIndex"
) )
elif self.entity_description.key == TYPE_FLOW_SENSOR_WATERING_CLICKS: elif self.entity_description.key == TYPE_FLOW_SENSOR_WATERING_CLICKS:
self._attr_native_value = self.coordinator.data["system"].get( self._attr_native_value = self.coordinator.data.get("system", {}).get(
"flowSensorWateringClicks" "flowSensorWateringClicks"
) )

View file

@ -2121,7 +2121,7 @@ raincloudy==0.0.7
raspyrfm-client==1.2.8 raspyrfm-client==1.2.8
# homeassistant.components.rainmachine # homeassistant.components.rainmachine
regenmaschine==2022.08.0 regenmaschine==2022.09.0
# homeassistant.components.renault # homeassistant.components.renault
renault-api==0.1.11 renault-api==0.1.11

View file

@ -1454,7 +1454,7 @@ radios==0.1.1
radiotherm==2.1.0 radiotherm==2.1.0
# homeassistant.components.rainmachine # homeassistant.components.rainmachine
regenmaschine==2022.08.0 regenmaschine==2022.09.0
# homeassistant.components.renault # homeassistant.components.renault
renault-api==0.1.11 renault-api==0.1.11