Skip to content

Commit

Permalink
Mark all constants as final
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 26, 2022
1 parent e6f4bbc commit f32fc5c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
16 changes: 8 additions & 8 deletions custom_components/iaquk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, Final, List, Optional, Union

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -61,9 +61,9 @@
)
from .sensor import SENSORS

_LOGGER = logging.getLogger(__name__)
_LOGGER: Final = logging.getLogger(__name__)

SOURCES = [
SOURCES: Final = [
CONF_TEMPERATURE,
CONF_HUMIDITY,
CONF_CO2,
Expand All @@ -75,9 +75,9 @@
CONF_PM,
]

SOURCES_LISTS = [CONF_PM]
SOURCES_LISTS: Final = [CONF_PM]

SOURCES_SCHEMA = vol.All(
SOURCES_SCHEMA: Final = vol.All(
vol.Schema(
{
vol.Optional(src): (cv.entity_ids if src in SOURCES_LISTS else cv.entity_id)
Expand All @@ -87,15 +87,15 @@
cv.has_at_least_one_key(*SOURCES),
)

IAQ_SCHEMA = vol.Schema(
IAQ_SCHEMA: Final = vol.Schema(
{
vol.Optional(CONF_NAME): cv.string,
vol.Required(CONF_SOURCES): SOURCES_SCHEMA,
vol.Optional(CONF_SENSORS): vol.All(cv.ensure_list, [vol.In(SENSORS)]),
}
)

CONFIG_SCHEMA = vol.Schema(
CONFIG_SCHEMA: Final = vol.Schema(
{DOMAIN: cv.schema_with_slug_keys(IAQ_SCHEMA)}, extra=vol.ALLOW_EXTRA
)

Expand Down Expand Up @@ -245,7 +245,7 @@ def update(self):
indexes = {}
for src in self._sources:
try:
idx = self.__getattribute__("_%s_index" % src)
idx = self.__getattribute__(f"_{src}_index")
_LOGGER.debug("[%s] %s_index=%s", self._entity_id, src, idx)
if idx is not None:
iaq += idx
Expand Down
83 changes: 41 additions & 42 deletions custom_components/iaquk/const.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Constants for calculate IAQ UK index."""
from typing import Final

from homeassistant.components.sensor import DOMAIN as SENSOR

# Base component constants
NAME = "Indoor Air Quality UK Index"
DOMAIN = "iaquk"
VERSION = "1.6.1"
ISSUE_URL = "https://github.com/Limych/ha-iaquk/issues"
NAME: Final = "Indoor Air Quality UK Index"
DOMAIN: Final = "iaquk"
VERSION: Final = "1.6.2-alpha"
ISSUE_URL: Final = "https://github.com/Limych/ha-iaquk/issues"

STARTUP_MESSAGE = f"""
STARTUP_MESSAGE: Final = f"""
-------------------------------------------------------------------
{NAME}
Version: {VERSION}
Expand All @@ -19,62 +20,60 @@
"""

# Icons
ICON_DEFAULT = "mdi:air-filter"
ICON_EXCELLENT = "mdi:emoticon-excited"
ICON_GOOD = "mdi:emoticon-happy"
ICON_FAIR = "mdi:emoticon-neutral"
ICON_POOR = "mdi:emoticon-sad"
ICON_INADEQUATE = "mdi:emoticon-dead"
ICON_DEFAULT: Final = "mdi:air-filter"
ICON_EXCELLENT: Final = "mdi:emoticon-excited"
ICON_GOOD: Final = "mdi:emoticon-happy"
ICON_FAIR: Final = "mdi:emoticon-neutral"
ICON_POOR: Final = "mdi:emoticon-sad"
ICON_INADEQUATE: Final = "mdi:emoticon-dead"

# Device classes
BINARY_SENSOR_DEVICE_CLASS = "connectivity"
BINARY_SENSOR_DEVICE_CLASS: Final = "connectivity"

# Platforms
PLATFORMS = [SENSOR]
PLATFORMS: Final = [SENSOR]

# Configuration and options
CONF_SOURCES = "sources"
CONF_TEMPERATURE = "temperature"
CONF_HUMIDITY = "humidity"
CONF_CO2 = "co2"
CONF_TVOC = "tvoc"
CONF_PM = "pm"
CONF_NO2 = "no2"
CONF_CO = "co"
CONF_HCHO = "hcho" # Formaldehyde
CONF_RADON = "radon"

# Defaults
CONF_SOURCES: Final = "sources"
CONF_TEMPERATURE: Final = "temperature"
CONF_HUMIDITY: Final = "humidity"
CONF_CO2: Final = "co2"
CONF_TVOC: Final = "tvoc"
CONF_PM: Final = "pm"
CONF_NO2: Final = "no2"
CONF_CO: Final = "co"
CONF_HCHO: Final = "hcho" # Formaldehyde
CONF_RADON: Final = "radon"

# Attributes
ATTR_SOURCES_SET = "sources_set"
ATTR_SOURCES_USED = "sources_used"
ATTR_SOURCE_INDEX_TPL = "{}_index"
ATTR_SOURCES_SET: Final = "sources_set"
ATTR_SOURCES_USED: Final = "sources_used"
ATTR_SOURCE_INDEX_TPL: Final = "{}_index"


LEVEL_EXCELLENT = "Excellent"
LEVEL_GOOD = "Good"
LEVEL_FAIR = "Fair"
LEVEL_POOR = "Poor"
LEVEL_INADEQUATE = "Inadequate"
LEVEL_EXCELLENT: Final = "Excellent"
LEVEL_GOOD: Final = "Good"
LEVEL_FAIR: Final = "Fair"
LEVEL_POOR: Final = "Poor"
LEVEL_INADEQUATE: Final = "Inadequate"

UNIT_PPM = {
UNIT_PPM: Final = {
"ppm": 1, # Target unit -- conversion rate will be ignored
"ppb": 0.001,
}
UNIT_PPB = {
UNIT_PPB: Final = {
"ppb": 1, # Target unit -- conversion rate will be ignored
"ppm": 1000,
}
UNIT_UGM3 = {
UNIT_UGM3: Final = {
"µg/m³": 1, # Target unit -- conversion rate will be ignored
"µg/m3": 1,
"µg/m^3": 1,
"mg/m³": 1000,
"mg/m3": 1000,
"mg/m^3": 1000,
}
UNIT_MGM3 = {
UNIT_MGM3: Final = {
"mg/m³": 1, # Target unit -- conversion rate will be ignored
"mg/m3": 1,
"mg/m^3": 1,
Expand All @@ -83,8 +82,8 @@
"µg/m^3": 0.001,
}

MWEIGTH_TVOC = 100 # g/mol
MWEIGTH_HCHO = 30.0260 # g/mol
MWEIGTH_CO = 28.0100 # g/mol
MWEIGTH_NO2 = 46.0100 # g/mol
MWEIGTH_CO2 = 44.0100 # g/mol
MWEIGTH_TVOC: Final = 100 # g/mol
MWEIGTH_HCHO: Final = 30.0260 # g/mol
MWEIGTH_CO: Final = 28.0100 # g/mol
MWEIGTH_NO2: Final = 46.0100 # g/mol
MWEIGTH_CO2: Final = 44.0100 # g/mol
2 changes: 1 addition & 1 deletion custom_components/iaquk/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "iaquk",
"name": "Indoor Air Quality UK Index",
"version": "1.6.1",
"version": "1.6.2-alpha",
"documentation": "https://github.com/Limych/ha-iaquk",
"issue_tracker": "https://github.com/Limych/ha-iaquk/issues",
"dependencies": [],
Expand Down
14 changes: 7 additions & 7 deletions custom_components/iaquk/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Sensor platform to calculate IAQ UK index."""

import logging
from typing import Any, Mapping, Optional
from typing import Any, Final, Mapping, Optional

from homeassistant.components.sensor import (
ENTITY_ID_FORMAT,
Expand All @@ -27,18 +27,18 @@
LEVEL_POOR,
)

_LOGGER = logging.getLogger(__name__)
_LOGGER: Final = logging.getLogger(__name__)

SENSOR_INDEX = "iaq_index"
SENSOR_LEVEL = "iaq_level"
SENSOR_INDEX: Final = "iaq_index"
SENSOR_LEVEL: Final = "iaq_level"

SENSORS = {
SENSORS: Final = {
SENSOR_INDEX: "Indoor Air Quality Index",
SENSOR_LEVEL: "Indoor Air Quality Level",
}


# pylint: disable=w0613
# pylint: disable=unused-argument
async def async_setup_platform(
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
):
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, controller, sensor_type: str):
)

self._attr_unique_id = f"{controller.unique_id}_{sensor_type}"
self._attr_name = "{} {}".format(controller.name, SENSORS[sensor_type])
self._attr_name = f"{controller.name} {SENSORS[sensor_type]}"
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_device_class = (
f"{DOMAIN}__level" if sensor_type == SENSOR_LEVEL else None
Expand Down

0 comments on commit f32fc5c

Please sign in to comment.