1 """Flo device object."""
3 from __future__
import annotations
6 from datetime
import datetime, timedelta
9 from aioflo.api
import API
10 from aioflo.errors
import RequestError
11 from orjson
import JSONDecodeError
17 from .const
import DOMAIN
as FLO_DOMAIN, LOGGER
21 """Flo device object."""
23 _failure_count: int = 0
26 self, hass: HomeAssistant, api_client: API, location_id: str, device_id: str
28 """Initialize the device."""
29 self.
hasshass: HomeAssistant = hass
30 self.api_client: API = api_client
31 self._flo_location_id: str = location_id
32 self._flo_device_id: str = device_id
33 self._manufacturer: str =
"Flo by Moen"
39 name=f
"{FLO_DOMAIN}-{device_id}",
44 """Update data via library."""
46 async
with asyncio.timeout(20):
51 except (RequestError, TimeoutError, JSONDecodeError)
as error:
58 """Return Flo location id."""
59 return self._flo_location_id
63 """Return Flo device id."""
64 return self._flo_device_id
68 """Return device name."""
70 "nickname", f
"{self.manufacturer} {self.model}"
75 """Return manufacturer for device."""
76 return self._manufacturer
80 """Return ieee address for device."""
85 """Return model for device."""
90 """Return rssi for device."""
95 """Return lastHeardFromTime for device."""
100 """Return the device type for the device."""
105 """Return True if device is available."""
110 """Return the current system mode."""
115 """Return the target system mode."""
120 """Return current flow rate in gpm."""
125 """Return the current pressure in psi."""
130 """Return the current temperature in degrees F."""
135 """Return the current humidity in percent (0-100)."""
140 """Return the current consumption for today in gallons."""
141 return self.
_water_usage_water_usage[
"aggregations"][
"sumTotalGallonsConsumed"]
145 """Return the firmware version for the device."""
150 """Return the serial number for the device."""
155 """Return the number of pending info alerts for the device."""
156 return self.
_device_information_device_information[
"notifications"][
"pending"][
"infoCount"]
160 """Return the number of pending warning alerts for the device."""
161 return self.
_device_information_device_information[
"notifications"][
"pending"][
"warningCount"]
165 """Return the number of pending critical alerts for the device."""
166 return self.
_device_information_device_information[
"notifications"][
"pending"][
"criticalCount"]
170 """Return True if any alert counts are greater than zero."""
179 """Return whether water is detected, for leak detectors."""
184 """Return the last known valve state for the device."""
189 """Return the target valve state for the device."""
194 """Return the battery level for battery-powered device, e.g. leak detectors."""
198 """Send Flo a presence ping."""
199 await self.api_client.presence.ping()
202 """Set the Flo location to home mode."""
203 await self.api_client.location.set_mode_home(self._flo_location_id)
206 """Set the Flo location to away mode."""
207 await self.api_client.location.set_mode_away(self._flo_location_id)
210 """Set the Flo location to sleep mode."""
211 await self.api_client.location.set_mode_sleep(
212 self._flo_location_id, sleep_minutes, revert_to_mode
216 """Run a Flo device health test."""
217 await self.api_client.device.run_health_test(self._flo_device_id)
220 """Update the device information from the API."""
227 """Update water consumption data from the API."""
228 today = dt_util.now().
date()
229 start_date =
datetime(today.year, today.month, today.day, 0, 0)
230 end_date =
datetime(today.year, today.month, today.day, 23, 59, 59, 999000)
231 self.
_water_usage_water_usage = await self.api_client.water.get_consumption_info(
232 self._flo_location_id, start_date, end_date
234 LOGGER.debug(
"Updated Flo consumption data: %s", self.
_water_usage_water_usage)
None _update_device(self, *_)
float battery_level(self)
str target_valve_state(self)
int pending_warning_alerts_count(self)
float current_flow_rate(self)
None __init__(self, HomeAssistant hass, API api_client, str location_id, str device_id)
float consumption_today(self)
def async_run_health_test(self)
str last_known_valve_state(self)
def async_set_mode_away(self)
str last_heard_from_time(self)
int pending_critical_alerts_count(self)
None _update_consumption_data(self, *_)
def async_set_mode_home(self)
str target_system_mode(self)
def async_set_mode_sleep(self, sleep_minutes, revert_to_mode)
def _async_update_data(self)
str|None serial_number(self)
bool water_detected(self)
def send_presence_ping(self)
str firmware_version(self)
str current_system_mode(self)
int pending_info_alerts_count(self)
web.Response get(self, web.Request request, str config_key)
datetime_sys datetime(Any value)