Introduce const file in LaMetric (#66929)
This commit is contained in:
parent
94a0f1c7b3
commit
ddedaf6f70
3 changed files with 42 additions and 34 deletions
|
@ -1,7 +1,6 @@
|
|||
"""Support for LaMetric notifications."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from lmnotify import Model, SimpleFrame, Sound
|
||||
|
@ -20,17 +19,17 @@ from homeassistant.core import HomeAssistant
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, HassLaMetricManager
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
AVAILABLE_PRIORITIES = ["info", "warning", "critical"]
|
||||
AVAILABLE_ICON_TYPES = ["none", "info", "alert"]
|
||||
|
||||
CONF_CYCLES = "cycles"
|
||||
CONF_LIFETIME = "lifetime"
|
||||
CONF_PRIORITY = "priority"
|
||||
CONF_ICON_TYPE = "icon_type"
|
||||
from . import HassLaMetricManager
|
||||
from .const import (
|
||||
AVAILABLE_ICON_TYPES,
|
||||
AVAILABLE_PRIORITIES,
|
||||
CONF_CYCLES,
|
||||
CONF_ICON_TYPE,
|
||||
CONF_LIFETIME,
|
||||
CONF_PRIORITY,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
|
@ -85,7 +84,7 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
data = kwargs.get(ATTR_DATA)
|
||||
_LOGGER.debug("Targets/Data: %s/%s", targets, data)
|
||||
LOGGER.debug("Targets/Data: %s/%s", targets, data)
|
||||
icon = self._icon
|
||||
cycles = self._cycles
|
||||
sound = None
|
||||
|
@ -99,16 +98,16 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||
if "sound" in data:
|
||||
try:
|
||||
sound = Sound(category="notifications", sound_id=data["sound"])
|
||||
_LOGGER.debug("Adding notification sound %s", data["sound"])
|
||||
LOGGER.debug("Adding notification sound %s", data["sound"])
|
||||
except AssertionError:
|
||||
_LOGGER.error("Sound ID %s unknown, ignoring", data["sound"])
|
||||
LOGGER.error("Sound ID %s unknown, ignoring", data["sound"])
|
||||
if "cycles" in data:
|
||||
cycles = int(data["cycles"])
|
||||
if "icon_type" in data:
|
||||
if data["icon_type"] in AVAILABLE_ICON_TYPES:
|
||||
icon_type = data["icon_type"]
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
LOGGER.warning(
|
||||
"Priority %s invalid, using default %s",
|
||||
data["priority"],
|
||||
priority,
|
||||
|
@ -117,13 +116,13 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||
if data["priority"] in AVAILABLE_PRIORITIES:
|
||||
priority = data["priority"]
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
LOGGER.warning(
|
||||
"Priority %s invalid, using default %s",
|
||||
data["priority"],
|
||||
priority,
|
||||
)
|
||||
text_frame = SimpleFrame(icon, message)
|
||||
_LOGGER.debug(
|
||||
LOGGER.debug(
|
||||
"Icon/Message/Cycles/Lifetime: %s, %s, %d, %d",
|
||||
icon,
|
||||
message,
|
||||
|
@ -138,11 +137,11 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||
try:
|
||||
self._devices = lmn.get_devices()
|
||||
except TokenExpiredError:
|
||||
_LOGGER.debug("Token expired, fetching new token")
|
||||
LOGGER.debug("Token expired, fetching new token")
|
||||
lmn.get_token()
|
||||
self._devices = lmn.get_devices()
|
||||
except RequestsConnectionError:
|
||||
_LOGGER.warning(
|
||||
LOGGER.warning(
|
||||
"Problem connecting to LaMetric, using cached devices instead"
|
||||
)
|
||||
for dev in self._devices:
|
||||
|
@ -155,6 +154,6 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||
priority=priority,
|
||||
icon_type=icon_type,
|
||||
)
|
||||
_LOGGER.debug("Sent notification to LaMetric %s", dev["name"])
|
||||
LOGGER.debug("Sent notification to LaMetric %s", dev["name"])
|
||||
except OSError:
|
||||
_LOGGER.warning("Cannot connect to LaMetric %s", dev["name"])
|
||||
LOGGER.warning("Cannot connect to LaMetric %s", dev["name"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue