From 3d6d650a16ae7bcb6c8f369bc766b8c257a7b230 Mon Sep 17 00:00:00 2001 From: David Knowles Date: Mon, 22 May 2023 09:11:32 -0400 Subject: [PATCH] Move Hydrawise constants into const.py (#93357) --- .../components/hydrawise/__init__.py | 31 +++++++------------ .../components/hydrawise/binary_sensor.py | 9 ++---- homeassistant/components/hydrawise/const.py | 20 ++++++++++++ homeassistant/components/hydrawise/sensor.py | 11 +++---- homeassistant/components/hydrawise/switch.py | 10 +++--- 5 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 homeassistant/components/hydrawise/const.py diff --git a/homeassistant/components/hydrawise/__init__.py b/homeassistant/components/hydrawise/__init__.py index a99c19cd46a..8f1217e25a1 100644 --- a/homeassistant/components/hydrawise/__init__.py +++ b/homeassistant/components/hydrawise/__init__.py @@ -1,6 +1,4 @@ """Support for Hydrawise cloud.""" -from datetime import timedelta -import logging from hydrawiser.core import Hydrawiser from requests.exceptions import ConnectTimeout, HTTPError @@ -15,22 +13,15 @@ from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.event import track_time_interval from homeassistant.helpers.typing import ConfigType -_LOGGER = logging.getLogger(__name__) - -ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60] - -CONF_WATERING_TIME = "watering_minutes" - -NOTIFICATION_ID = "hydrawise_notification" -NOTIFICATION_TITLE = "Hydrawise Setup" - -DATA_HYDRAWISE = "hydrawise" -DOMAIN = "hydrawise" -DEFAULT_WATERING_TIME = 15 - -SCAN_INTERVAL = timedelta(seconds=120) - -SIGNAL_UPDATE_HYDRAWISE = "hydrawise_update" +from .const import ( + DATA_HYDRAWISE, + DOMAIN, + LOGGER, + NOTIFICATION_ID, + NOTIFICATION_TITLE, + SCAN_INTERVAL, + SIGNAL_UPDATE_HYDRAWISE, +) CONFIG_SCHEMA = vol.Schema( { @@ -55,7 +46,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: hydrawise = Hydrawiser(user_token=access_token) hass.data[DATA_HYDRAWISE] = HydrawiseHub(hydrawise) except (ConnectTimeout, HTTPError) as ex: - _LOGGER.error("Unable to connect to Hydrawise cloud service: %s", str(ex)) + LOGGER.error("Unable to connect to Hydrawise cloud service: %s", str(ex)) persistent_notification.create( hass, f"Error: {ex}
You will need to restart hass after fixing.", @@ -66,7 +57,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: def hub_refresh(event_time): """Call Hydrawise hub to refresh information.""" - _LOGGER.debug("Updating Hydrawise Hub component") + LOGGER.debug("Updating Hydrawise Hub component") hass.data[DATA_HYDRAWISE].data.update_controller_info() dispatcher_send(hass, SIGNAL_UPDATE_HYDRAWISE) diff --git a/homeassistant/components/hydrawise/binary_sensor.py b/homeassistant/components/hydrawise/binary_sensor.py index 3b496355a56..832820fbcc7 100644 --- a/homeassistant/components/hydrawise/binary_sensor.py +++ b/homeassistant/components/hydrawise/binary_sensor.py @@ -1,8 +1,6 @@ """Support for Hydrawise sprinkler binary sensors.""" from __future__ import annotations -import logging - import voluptuous as vol from homeassistant.components.binary_sensor import ( @@ -17,9 +15,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import DATA_HYDRAWISE, HydrawiseEntity - -_LOGGER = logging.getLogger(__name__) +from . import HydrawiseEntity +from .const import DATA_HYDRAWISE, LOGGER BINARY_SENSOR_STATUS = BinarySensorEntityDescription( key="status", @@ -82,7 +79,7 @@ class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity): def update(self) -> None: """Get the latest data and updates the state.""" - _LOGGER.debug("Updating Hydrawise binary sensor: %s", self.name) + LOGGER.debug("Updating Hydrawise binary sensor: %s", self.name) mydata = self.hass.data[DATA_HYDRAWISE].data if self.entity_description.key == "status": self._attr_is_on = mydata.status == "All good!" diff --git a/homeassistant/components/hydrawise/const.py b/homeassistant/components/hydrawise/const.py new file mode 100644 index 00000000000..5a046530f01 --- /dev/null +++ b/homeassistant/components/hydrawise/const.py @@ -0,0 +1,20 @@ +"""Constants for the Hydrawise integration.""" + +from datetime import timedelta +import logging + +LOGGER = logging.getLogger(__package__) + +ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60] +CONF_WATERING_TIME = "watering_minutes" + +NOTIFICATION_ID = "hydrawise_notification" +NOTIFICATION_TITLE = "Hydrawise Setup" + +DATA_HYDRAWISE = "hydrawise" +DOMAIN = "hydrawise" +DEFAULT_WATERING_TIME = 15 + +SCAN_INTERVAL = timedelta(seconds=120) + +SIGNAL_UPDATE_HYDRAWISE = "hydrawise_update" diff --git a/homeassistant/components/hydrawise/sensor.py b/homeassistant/components/hydrawise/sensor.py index 3114a50673f..0b765d5d338 100644 --- a/homeassistant/components/hydrawise/sensor.py +++ b/homeassistant/components/hydrawise/sensor.py @@ -1,8 +1,6 @@ """Support for Hydrawise sprinkler sensors.""" from __future__ import annotations -import logging - import voluptuous as vol from homeassistant.components.sensor import ( @@ -18,9 +16,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt -from . import DATA_HYDRAWISE, HydrawiseEntity - -_LOGGER = logging.getLogger(__name__) +from . import HydrawiseEntity +from .const import DATA_HYDRAWISE, LOGGER SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( @@ -76,7 +73,7 @@ class HydrawiseSensor(HydrawiseEntity, SensorEntity): def update(self) -> None: """Get the latest data and updates the states.""" mydata = self.hass.data[DATA_HYDRAWISE].data - _LOGGER.debug("Updating Hydrawise sensor: %s", self.name) + LOGGER.debug("Updating Hydrawise sensor: %s", self.name) relay_data = mydata.relays[self.data["relay"] - 1] if self.entity_description.key == "watering_time": if relay_data["timestr"] == "Now": @@ -85,7 +82,7 @@ class HydrawiseSensor(HydrawiseEntity, SensorEntity): self._attr_native_value = 0 else: # _sensor_type == 'next_cycle' next_cycle = min(relay_data["time"], TWO_YEAR_SECONDS) - _LOGGER.debug("New cycle time: %s", next_cycle) + LOGGER.debug("New cycle time: %s", next_cycle) self._attr_native_value = dt.utc_from_timestamp( dt.as_timestamp(dt.now()) + next_cycle ) diff --git a/homeassistant/components/hydrawise/switch.py b/homeassistant/components/hydrawise/switch.py index cc12638f329..f075b334cd5 100644 --- a/homeassistant/components/hydrawise/switch.py +++ b/homeassistant/components/hydrawise/switch.py @@ -1,7 +1,6 @@ """Support for Hydrawise cloud switches.""" from __future__ import annotations -import logging from typing import Any import voluptuous as vol @@ -18,16 +17,15 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import ( +from . import HydrawiseEntity +from .const import ( ALLOWED_WATERING_TIME, CONF_WATERING_TIME, DATA_HYDRAWISE, DEFAULT_WATERING_TIME, - HydrawiseEntity, + LOGGER, ) -_LOGGER = logging.getLogger(__name__) - SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = ( SwitchEntityDescription( key="auto_watering", @@ -108,7 +106,7 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity): """Update device state.""" relay_data = self.data["relay"] - 1 mydata = self.hass.data[DATA_HYDRAWISE].data - _LOGGER.debug("Updating Hydrawise switch: %s", self.name) + LOGGER.debug("Updating Hydrawise switch: %s", self.name) if self.entity_description.key == "manual_watering": self._attr_is_on = mydata.relays[relay_data]["timestr"] == "Now" elif self.entity_description.key == "auto_watering":