Skip to content

Commit

Permalink
Update formatting/linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Feb 3, 2022
1 parent ace44bb commit 576efe3
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions custom_components/bhyve/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
)

SET_SMART_WATERING_SOIL_MOISTURE_SCHEMA = SERVICE_BASE_SCHEMA.extend(
{vol.Required(ATTR_PERCENTAGE): cv.positive_int,}
{
vol.Required(ATTR_PERCENTAGE): cv.positive_int,
}
)

SERVICE_ENABLE_RAIN_DELAY = "enable_rain_delay"
Expand Down Expand Up @@ -515,7 +517,7 @@ async def _send_station_message(self, station_payload):

except BHyveError as err:
_LOGGER.warning("Failed to send to BHyve websocket message %s", err)
raise (err)
raise err

@property
def entity_picture(self):
Expand All @@ -537,40 +539,54 @@ async def set_smart_watering_soil_moisture(self, percentage):
if self._smart_watering_enabled:
landscape = None
try:
landscape = await self._bhyve.get_landscape(self._device_id, self._zone_id)

landscape = await self._bhyve.get_landscape(
self._device_id, self._zone_id
)

except BHyveError as err:
_LOGGER.warning(f"Unable to retreive current soil data for {self.name}: {err}")

_LOGGER.warning(
"Unable to retreive current soil data for %s: %s", self.name, err
)

if landscape is not None:
_LOGGER.debug("Landscape data %s", landscape)

# Define the minimum landscape update json payload
landscape_update = {
"current_water_level": 0,
"device_id": "",
"id": "",
"station": 0
"device_id": self._device_id,
"id": landscape.get("id"),
"station": self._zone_id,
}

landscape_moisture_level_0 = landscape['replenishment_point'] # B-hyve computed value for 0% moisture
landscape_moisture_level_100 = landscape['field_capacity_depth'] # B-hyve computed value for 100% moisture
# Set property to computed user desired soil moisture level
landscape_update['current_water_level'] = (landscape_moisture_level_0
+ ((percentage * (landscape_moisture_level_100 - landscape_moisture_level_0)) / 100.0))
# Set remaining properties
landscape_update['device_id'] = self._device_id
landscape_update['id'] = landscape['id']
landscape_update['station'] = self._zone_id
landscape_moisture_level_0 = landscape[
"replenishment_point"
] # B-hyve computed value for 0% moisture
landscape_moisture_level_100 = landscape[
"field_capacity_depth"
] # B-hyve computed value for 100% moisture
# Set property to computed user desired soil moisture level
landscape_update["current_water_level"] = landscape_moisture_level_0 + (
(
percentage
* (landscape_moisture_level_100 - landscape_moisture_level_0)
)
/ 100.0
)

try:
_LOGGER.debug("Landscape update %s", landscape_update)
await self._bhyve.update_landscape(landscape_update)

except BHyveError as err:
_LOGGER.warning(f"Unable to set soil moisture level for {self.name}: {err}")
_LOGGER.warning(
"Unable to set soil moisture level for %s: %s", self.name, err
)
else:
_LOGGER.info("Zone %s isn't smart watering enabled, cannot set soil moisture.", self._zone_name)
_LOGGER.info(
"Zone %s isn't smart watering enabled, cannot set soil moisture.",
self._zone_name,
)

async def start_watering(self, minutes):
"""Start watering program"""
Expand Down Expand Up @@ -634,7 +650,8 @@ def _on_ws_data(self, data):
if event is None:
_LOGGER.warning("No event on ws data %s", data)
return
elif event == EVENT_RAIN_DELAY:

if event == EVENT_RAIN_DELAY:
self._extract_rain_delay(
data.get("delay"), {"rain_delay_started_at": data.get("timestamp")}
)
Expand Down

0 comments on commit 576efe3

Please sign in to comment.