Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Hydrawise constants into const.py #93357

Merged
merged 1 commit into from
May 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 11 additions & 20 deletions homeassistant/components/hydrawise/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,22 +13,15 @@
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(
{
Expand All @@ -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}<br />You will need to restart hass after fixing.",
Expand All @@ -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)

Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/hydrawise/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -17,9 +15,8 @@
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",
Expand Down Expand Up @@ -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!"
Expand Down
20 changes: 20 additions & 0 deletions homeassistant/components/hydrawise/const.py
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 4 additions & 7 deletions homeassistant/components/hydrawise/sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Support for Hydrawise sprinkler sensors."""
from __future__ import annotations

import logging

import voluptuous as vol

from homeassistant.components.sensor import (
Expand All @@ -18,9 +16,8 @@
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(
Expand Down Expand Up @@ -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":
Expand All @@ -85,7 +82,7 @@ def update(self) -> None:
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
)
10 changes: 4 additions & 6 deletions homeassistant/components/hydrawise/switch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for Hydrawise cloud switches."""
from __future__ import annotations

import logging
from typing import Any

import voluptuous as vol
Expand All @@ -18,16 +17,15 @@
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",
Expand Down Expand Up @@ -108,7 +106,7 @@ def update(self) -> None:
"""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":
Expand Down