Enable strict type checks for onewire (#50422)
This commit is contained in:
parent
efa5c59559
commit
d6c99a3db9
13 changed files with 202 additions and 84 deletions
|
@ -1,14 +1,21 @@
|
|||
"""Support for 1-Wire binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_TYPE_OWSERVER, DOMAIN, SENSOR_TYPE_SENSED
|
||||
from .onewire_entities import OneWireProxyEntity
|
||||
from .model import DeviceComponentDescription
|
||||
from .onewire_entities import OneWireBaseEntity, OneWireProxyEntity
|
||||
from .onewirehub import OneWireHub
|
||||
|
||||
DEVICE_BINARY_SENSORS = {
|
||||
DEVICE_BINARY_SENSORS: dict[str, list[DeviceComponentDescription]] = {
|
||||
# Family : { path, sensor_type }
|
||||
"12": [
|
||||
{
|
||||
|
@ -77,7 +84,11 @@ DEVICE_BINARY_SENSORS = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up 1-Wire platform."""
|
||||
# Only OWServer implementation works with binary sensors
|
||||
if config_entry.data[CONF_TYPE] == CONF_TYPE_OWSERVER:
|
||||
|
@ -87,9 +98,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(onewirehub: OneWireHub):
|
||||
def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
"""Get a list of entities."""
|
||||
entities = []
|
||||
if not onewirehub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireBaseEntity] = []
|
||||
|
||||
for device in onewirehub.devices:
|
||||
family = device["family"]
|
||||
|
@ -98,7 +112,7 @@ def get_entities(onewirehub: OneWireHub):
|
|||
|
||||
if family not in DEVICE_BINARY_SENSORS:
|
||||
continue
|
||||
device_info = {
|
||||
device_info: DeviceInfo = {
|
||||
"identifiers": {(DOMAIN, device_id)},
|
||||
"manufacturer": "Maxim Integrated",
|
||||
"model": device_type,
|
||||
|
@ -126,6 +140,6 @@ class OneWireProxyBinarySensor(OneWireProxyEntity, BinarySensorEntity):
|
|||
"""Implementation of a 1-Wire binary sensor."""
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if sensor is on."""
|
||||
return self._state
|
||||
return bool(self._state)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue