From b9daa2289138dc7843b0eb719557f639404349c8 Mon Sep 17 00:00:00 2001 From: Phil Cole Date: Sun, 2 Jan 2022 17:48:33 +0000 Subject: [PATCH] Introduce const file in Nissan Leaf (#63082) * Introduce const file in Nissan Leaf * Use final * Don't alter start_charging logic * Don't centralise logger --- .../components/nissan_leaf/__init__.py | 53 +++++++++---------- .../components/nissan_leaf/binary_sensor.py | 3 +- homeassistant/components/nissan_leaf/const.py | 35 ++++++++++++ .../components/nissan_leaf/sensor.py | 4 +- .../components/nissan_leaf/switch.py | 3 +- 5 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 homeassistant/components/nissan_leaf/const.py diff --git a/homeassistant/components/nissan_leaf/__init__.py b/homeassistant/components/nissan_leaf/__init__.py index 7e8dd5c2efb..9c9f2f484ef 100644 --- a/homeassistant/components/nissan_leaf/__init__.py +++ b/homeassistant/components/nissan_leaf/__init__.py @@ -28,36 +28,33 @@ from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.typing import ConfigType from homeassistant.util.dt import utcnow +from .const import ( + CONF_CHARGING_INTERVAL, + CONF_CLIMATE_INTERVAL, + CONF_FORCE_MILES, + CONF_INTERVAL, + CONF_VALID_REGIONS, + DATA_BATTERY, + DATA_CHARGING, + DATA_CLIMATE, + DATA_LEAF, + DATA_PLUGGED_IN, + DATA_RANGE_AC, + DATA_RANGE_AC_OFF, + DEFAULT_CHARGING_INTERVAL, + DEFAULT_CLIMATE_INTERVAL, + DEFAULT_INTERVAL, + DOMAIN, + INITIAL_UPDATE, + MAX_RESPONSE_ATTEMPTS, + MIN_UPDATE_INTERVAL, + PYCARWINGS2_SLEEP, + RESTRICTED_BATTERY, + RESTRICTED_INTERVAL, +) + _LOGGER = logging.getLogger(__name__) -DOMAIN = "nissan_leaf" -DATA_LEAF = "nissan_leaf_data" - -DATA_BATTERY = "battery" -DATA_CHARGING = "charging" -DATA_PLUGGED_IN = "plugged_in" -DATA_CLIMATE = "climate" -DATA_RANGE_AC = "range_ac_on" -DATA_RANGE_AC_OFF = "range_ac_off" - -CONF_INTERVAL = "update_interval" -CONF_CHARGING_INTERVAL = "update_interval_charging" -CONF_CLIMATE_INTERVAL = "update_interval_climate" -CONF_VALID_REGIONS = ["NNA", "NE", "NCI", "NMA", "NML"] -CONF_FORCE_MILES = "force_miles" - -INITIAL_UPDATE = timedelta(seconds=15) -MIN_UPDATE_INTERVAL = timedelta(minutes=2) -DEFAULT_INTERVAL = timedelta(hours=1) -DEFAULT_CHARGING_INTERVAL = timedelta(minutes=15) -DEFAULT_CLIMATE_INTERVAL = timedelta(minutes=5) -RESTRICTED_BATTERY = 2 -RESTRICTED_INTERVAL = timedelta(hours=12) - -MAX_RESPONSE_ATTEMPTS = 3 - -PYCARWINGS2_SLEEP = 30 - CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.All( diff --git a/homeassistant/components/nissan_leaf/binary_sensor.py b/homeassistant/components/nissan_leaf/binary_sensor.py index ba4bc62d7bd..518a7a657c7 100644 --- a/homeassistant/components/nissan_leaf/binary_sensor.py +++ b/homeassistant/components/nissan_leaf/binary_sensor.py @@ -13,7 +13,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import DATA_CHARGING, DATA_LEAF, DATA_PLUGGED_IN, LeafEntity +from . import LeafEntity +from .const import DATA_CHARGING, DATA_LEAF, DATA_PLUGGED_IN _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/nissan_leaf/const.py b/homeassistant/components/nissan_leaf/const.py new file mode 100644 index 00000000000..ed7d227184f --- /dev/null +++ b/homeassistant/components/nissan_leaf/const.py @@ -0,0 +1,35 @@ +"""Constants for the Nissan Leaf integration.""" +from __future__ import annotations + +from datetime import timedelta +from typing import Final + +DOMAIN: Final = "nissan_leaf" + +DATA_LEAF: Final = "nissan_leaf_data" + +DATA_BATTERY: Final = "battery" +DATA_CHARGING: Final = "charging" +DATA_PLUGGED_IN: Final = "plugged_in" +DATA_CLIMATE: Final = "climate" +DATA_RANGE_AC: Final = "range_ac_on" +DATA_RANGE_AC_OFF: Final = "range_ac_off" + +CONF_INTERVAL: Final = "update_interval" +CONF_CHARGING_INTERVAL: Final = "update_interval_charging" +CONF_CLIMATE_INTERVAL: Final = "update_interval_climate" +CONF_FORCE_MILES: Final = "force_miles" + +CONF_VALID_REGIONS: Final = ["NNA", "NE", "NCI", "NMA", "NML"] + +INITIAL_UPDATE: Final = timedelta(seconds=15) +MIN_UPDATE_INTERVAL: Final = timedelta(minutes=2) +DEFAULT_INTERVAL: Final = timedelta(hours=1) +DEFAULT_CHARGING_INTERVAL: Final = timedelta(minutes=15) +DEFAULT_CLIMATE_INTERVAL: Final = timedelta(minutes=5) +RESTRICTED_INTERVAL: Final = timedelta(hours=12) +RESTRICTED_BATTERY: Final = 2 + +MAX_RESPONSE_ATTEMPTS: Final = 3 + +PYCARWINGS2_SLEEP: Final = 30 diff --git a/homeassistant/components/nissan_leaf/sensor.py b/homeassistant/components/nissan_leaf/sensor.py index 746776979bc..c3786d2bd7f 100644 --- a/homeassistant/components/nissan_leaf/sensor.py +++ b/homeassistant/components/nissan_leaf/sensor.py @@ -15,13 +15,13 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util.distance import LENGTH_KILOMETERS, LENGTH_MILES from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM -from . import ( +from . import LeafEntity +from .const import ( DATA_BATTERY, DATA_CHARGING, DATA_LEAF, DATA_RANGE_AC, DATA_RANGE_AC_OFF, - LeafEntity, ) _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/nissan_leaf/switch.py b/homeassistant/components/nissan_leaf/switch.py index 40b4885b206..22c94274d8c 100644 --- a/homeassistant/components/nissan_leaf/switch.py +++ b/homeassistant/components/nissan_leaf/switch.py @@ -11,7 +11,8 @@ from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import DATA_CLIMATE, DATA_LEAF, LeafEntity +from . import LeafEntity +from .const import DATA_CLIMATE, DATA_LEAF _LOGGER = logging.getLogger(__name__)