mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix Shelly type hints (#50322)
This commit is contained in:
parent
4e4042a869
commit
be73067f9c
@ -90,8 +90,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
)
|
)
|
||||||
|
|
||||||
dev_reg = await device_registry.async_get_registry(hass)
|
dev_reg = await device_registry.async_get_registry(hass)
|
||||||
identifier = (DOMAIN, entry.unique_id)
|
device_entry = None
|
||||||
device_entry = dev_reg.async_get_device(identifiers={identifier}, connections=set())
|
if entry.unique_id is not None:
|
||||||
|
device_entry = dev_reg.async_get_device(
|
||||||
|
identifiers={(DOMAIN, entry.unique_id)}, connections=set()
|
||||||
|
)
|
||||||
if device_entry and entry.entry_id not in device_entry.config_entries:
|
if device_entry and entry.entry_id not in device_entry.config_entries:
|
||||||
device_entry = None
|
device_entry = None
|
||||||
|
|
||||||
@ -185,7 +188,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
self._async_remove_device_updates_handler = self.async_add_listener(
|
self._async_remove_device_updates_handler = self.async_add_listener(
|
||||||
self._async_device_updates_handler
|
self._async_device_updates_handler
|
||||||
)
|
)
|
||||||
self._last_input_events_count = {}
|
self._last_input_events_count: dict = {}
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
|
||||||
|
|
||||||
|
@ -81,3 +81,5 @@ SHBTN_MODELS = ["SHBTN-1", "SHBTN-2"]
|
|||||||
KELVIN_MAX_VALUE = 6500
|
KELVIN_MAX_VALUE = 6500
|
||||||
KELVIN_MIN_VALUE_WHITE = 2700
|
KELVIN_MIN_VALUE_WHITE = 2700
|
||||||
KELVIN_MIN_VALUE_COLOR = 3000
|
KELVIN_MIN_VALUE_COLOR = 3000
|
||||||
|
|
||||||
|
UPTIME_DEVIATION = 5
|
||||||
|
@ -178,7 +178,7 @@ class ShellyBlockEntity(entity.Entity):
|
|||||||
"""Initialize Shelly entity."""
|
"""Initialize Shelly entity."""
|
||||||
self.wrapper = wrapper
|
self.wrapper = wrapper
|
||||||
self.block = block
|
self.block = block
|
||||||
self._name = get_entity_name(wrapper.device, block)
|
self._name: str | None = get_entity_name(wrapper.device, block)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from aioshelly import Block
|
from aioshelly import Block
|
||||||
import async_timeout
|
import async_timeout
|
||||||
@ -212,7 +213,7 @@ class ShellyLight(ShellyBlockEntity, LightEntity):
|
|||||||
|
|
||||||
set_mode = None
|
set_mode = None
|
||||||
supported_color_modes = self._supported_color_modes
|
supported_color_modes = self._supported_color_modes
|
||||||
params = {"turn": "on"}
|
params: dict[str, Any] = {"turn": "on"}
|
||||||
|
|
||||||
if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
|
if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
|
||||||
brightness_pct = int(100 * (kwargs[ATTR_BRIGHTNESS] + 1) / 255)
|
brightness_pct = int(100 * (kwargs[ATTR_BRIGHTNESS] + 1) / 255)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Shelly helpers functions."""
|
"""Shelly helpers functions."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aioshelly
|
import aioshelly
|
||||||
@ -9,7 +9,7 @@ import aioshelly
|
|||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import singleton
|
from homeassistant.helpers import singleton
|
||||||
from homeassistant.util.dt import parse_datetime, utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
BASIC_INPUTS_EVENTS_TYPES,
|
BASIC_INPUTS_EVENTS_TYPES,
|
||||||
@ -21,6 +21,7 @@ from .const import (
|
|||||||
SHBTN_INPUTS_EVENTS_TYPES,
|
SHBTN_INPUTS_EVENTS_TYPES,
|
||||||
SHBTN_MODELS,
|
SHBTN_MODELS,
|
||||||
SHIX3_1_INPUTS_EVENTS_TYPES,
|
SHIX3_1_INPUTS_EVENTS_TYPES,
|
||||||
|
UPTIME_DEVIATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -118,6 +119,8 @@ def is_momentary_input(settings: dict, block: aioshelly.Block) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
button = settings.get("relays") or settings.get("lights") or settings.get("inputs")
|
button = settings.get("relays") or settings.get("lights") or settings.get("inputs")
|
||||||
|
if button is None:
|
||||||
|
return False
|
||||||
|
|
||||||
# Shelly 1L has two button settings in the first channel
|
# Shelly 1L has two button settings in the first channel
|
||||||
if settings["device"]["type"] == "SHSW-L":
|
if settings["device"]["type"] == "SHSW-L":
|
||||||
@ -133,13 +136,14 @@ def is_momentary_input(settings: dict, block: aioshelly.Block) -> bool:
|
|||||||
|
|
||||||
def get_device_uptime(status: dict, last_uptime: str) -> str:
|
def get_device_uptime(status: dict, last_uptime: str) -> str:
|
||||||
"""Return device uptime string, tolerate up to 5 seconds deviation."""
|
"""Return device uptime string, tolerate up to 5 seconds deviation."""
|
||||||
uptime = utcnow() - timedelta(seconds=status["uptime"])
|
delta_uptime = utcnow() - timedelta(seconds=status["uptime"])
|
||||||
|
|
||||||
if not last_uptime:
|
if (
|
||||||
return uptime.replace(microsecond=0).isoformat()
|
not last_uptime
|
||||||
|
or abs((delta_uptime - datetime.fromisoformat(last_uptime)).total_seconds())
|
||||||
if abs((uptime - parse_datetime(last_uptime)).total_seconds()) > 5:
|
> UPTIME_DEVIATION
|
||||||
return uptime.replace(microsecond=0).isoformat()
|
):
|
||||||
|
return delta_uptime.replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
return last_uptime
|
return last_uptime
|
||||||
|
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -1175,9 +1175,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.sharkiq.*]
|
[mypy-homeassistant.components.sharkiq.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.shelly.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.sma.*]
|
[mypy-homeassistant.components.sma.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -186,7 +186,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.sentry.*",
|
"homeassistant.components.sentry.*",
|
||||||
"homeassistant.components.sesame.*",
|
"homeassistant.components.sesame.*",
|
||||||
"homeassistant.components.sharkiq.*",
|
"homeassistant.components.sharkiq.*",
|
||||||
"homeassistant.components.shelly.*",
|
|
||||||
"homeassistant.components.sma.*",
|
"homeassistant.components.sma.*",
|
||||||
"homeassistant.components.smart_meter_texas.*",
|
"homeassistant.components.smart_meter_texas.*",
|
||||||
"homeassistant.components.smartthings.*",
|
"homeassistant.components.smartthings.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user