mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Fix type issues [firmata] (#67093)
This commit is contained in:
parent
636d791b37
commit
c11663344d
@ -190,7 +190,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
device_registry = dr.async_get(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
connections={},
|
||||
connections=set(),
|
||||
identifiers={(DOMAIN, board.name)},
|
||||
manufacturer=FIRMATA_MANUFACTURER,
|
||||
name=board.name,
|
||||
|
@ -1,6 +1,9 @@
|
||||
"""Code to handle a Firmata board."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Union
|
||||
from typing import Literal, Union
|
||||
|
||||
from pymata_express.pymata_express import PymataExpress
|
||||
from pymata_express.pymata_express_serial import serial
|
||||
@ -32,18 +35,18 @@ FirmataPinType = Union[int, str]
|
||||
class FirmataBoard:
|
||||
"""Manages a single Firmata board."""
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
def __init__(self, config: Mapping) -> None:
|
||||
"""Initialize the board."""
|
||||
self.config = config
|
||||
self.api = None
|
||||
self.firmware_version = None
|
||||
self.api: PymataExpress = None
|
||||
self.firmware_version: str | None = None
|
||||
self.protocol_version = None
|
||||
self.name = self.config[CONF_NAME]
|
||||
self.switches = []
|
||||
self.lights = []
|
||||
self.binary_sensors = []
|
||||
self.sensors = []
|
||||
self.used_pins = []
|
||||
self.used_pins: list[FirmataPinType] = []
|
||||
|
||||
if CONF_SWITCHES in self.config:
|
||||
self.switches = self.config[CONF_SWITCHES]
|
||||
@ -118,8 +121,10 @@ board %s: %s",
|
||||
self.used_pins.append(pin)
|
||||
return True
|
||||
|
||||
def get_pin_type(self, pin: FirmataPinType) -> tuple:
|
||||
def get_pin_type(self, pin: FirmataPinType) -> tuple[Literal[0, 1], int]:
|
||||
"""Return the type and Firmata location of a pin on the board."""
|
||||
pin_type: Literal[0, 1]
|
||||
firmata_pin: int
|
||||
if isinstance(pin, str):
|
||||
pin_type = PIN_TYPE_ANALOG
|
||||
firmata_pin = int(pin[1:])
|
||||
@ -130,7 +135,7 @@ board %s: %s",
|
||||
return (pin_type, firmata_pin)
|
||||
|
||||
|
||||
async def get_board(data: dict) -> PymataExpress:
|
||||
async def get_board(data: Mapping) -> PymataExpress:
|
||||
"""Create a Pymata board object."""
|
||||
board_data = {}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Constants for the Firmata component."""
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_BINARY_SENSORS,
|
||||
CONF_LIGHTS,
|
||||
@ -19,8 +21,8 @@ PIN_MODE_OUTPUT = "OUTPUT"
|
||||
PIN_MODE_PWM = "PWM"
|
||||
PIN_MODE_INPUT = "INPUT"
|
||||
PIN_MODE_PULLUP = "PULLUP"
|
||||
PIN_TYPE_ANALOG = 1
|
||||
PIN_TYPE_DIGITAL = 0
|
||||
PIN_TYPE_ANALOG: Final = 1
|
||||
PIN_TYPE_DIGITAL: Final = 0
|
||||
CONF_SAMPLING_INTERVAL = "sampling_interval"
|
||||
CONF_SERIAL_BAUD_RATE = "serial_baud_rate"
|
||||
CONF_SERIAL_PORT = "serial_port"
|
||||
|
@ -20,7 +20,7 @@ class FirmataEntity:
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return DeviceInfo(
|
||||
connections={},
|
||||
connections=set(),
|
||||
identifiers={(DOMAIN, self._api.board.name)},
|
||||
manufacturer=FIRMATA_MANUFACTURER,
|
||||
name=self._api.board.name,
|
||||
@ -33,7 +33,7 @@ class FirmataPinEntity(FirmataEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: type[FirmataBoardPin],
|
||||
api: FirmataBoardPin,
|
||||
config_entry: ConfigEntry,
|
||||
name: str,
|
||||
pin: FirmataPinType,
|
||||
|
@ -58,7 +58,7 @@ class FirmataLight(FirmataPinEntity, LightEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: type[FirmataBoardPin],
|
||||
api: FirmataBoardPin,
|
||||
config_entry: ConfigEntry,
|
||||
name: str,
|
||||
pin: FirmataPinType,
|
||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import logging
|
||||
from typing import cast
|
||||
|
||||
from .board import FirmataBoard, FirmataPinType
|
||||
from .const import PIN_MODE_INPUT, PIN_MODE_PULLUP, PIN_TYPE_ANALOG
|
||||
@ -23,11 +24,12 @@ class FirmataBoardPin:
|
||||
self._pin = pin
|
||||
self._pin_mode = pin_mode
|
||||
self._pin_type, self._firmata_pin = self.board.get_pin_type(self._pin)
|
||||
self._state = None
|
||||
self._state: bool | int | None = None
|
||||
self._analog_pin: int | None = None
|
||||
|
||||
if self._pin_type == PIN_TYPE_ANALOG:
|
||||
# Pymata wants the analog pin formatted as the # from "A#"
|
||||
self._analog_pin = int(self._pin[1:])
|
||||
self._analog_pin = int(cast(str, self._pin)[1:])
|
||||
|
||||
def setup(self):
|
||||
"""Set up a pin and make sure it is valid."""
|
||||
@ -38,6 +40,8 @@ class FirmataBoardPin:
|
||||
class FirmataBinaryDigitalOutput(FirmataBoardPin):
|
||||
"""Representation of a Firmata Digital Output Pin."""
|
||||
|
||||
_state: bool
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
board: FirmataBoard,
|
||||
@ -92,6 +96,8 @@ class FirmataBinaryDigitalOutput(FirmataBoardPin):
|
||||
class FirmataPWMOutput(FirmataBoardPin):
|
||||
"""Representation of a Firmata PWM/analog Output Pin."""
|
||||
|
||||
_state: int
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
board: FirmataBoard,
|
||||
@ -139,12 +145,14 @@ class FirmataPWMOutput(FirmataBoardPin):
|
||||
class FirmataBinaryDigitalInput(FirmataBoardPin):
|
||||
"""Representation of a Firmata Digital Input Pin."""
|
||||
|
||||
_state: bool
|
||||
|
||||
def __init__(
|
||||
self, board: FirmataBoard, pin: FirmataPinType, pin_mode: str, negate: bool
|
||||
) -> None:
|
||||
"""Initialize the digital input pin."""
|
||||
self._negate = negate
|
||||
self._forward_callback = None
|
||||
self._forward_callback: Callable[[], None]
|
||||
super().__init__(board, pin, pin_mode)
|
||||
|
||||
async def start_pin(self, forward_callback: Callable[[], None]) -> None:
|
||||
@ -206,12 +214,15 @@ class FirmataBinaryDigitalInput(FirmataBoardPin):
|
||||
class FirmataAnalogInput(FirmataBoardPin):
|
||||
"""Representation of a Firmata Analog Input Pin."""
|
||||
|
||||
_analog_pin: int
|
||||
_state: int
|
||||
|
||||
def __init__(
|
||||
self, board: FirmataBoard, pin: FirmataPinType, pin_mode: str, differential: int
|
||||
) -> None:
|
||||
"""Initialize the analog input pin."""
|
||||
self._differential = differential
|
||||
self._forward_callback = None
|
||||
self._forward_callback: Callable[[], None]
|
||||
super().__init__(board, pin, pin_mode)
|
||||
|
||||
async def start_pin(self, forward_callback: Callable[[], None]) -> None:
|
||||
|
24
mypy.ini
24
mypy.ini
@ -2273,30 +2273,6 @@ ignore_errors = true
|
||||
[mypy-homeassistant.components.fireservicerota.switch]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.binary_sensor]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.board]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.entity]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.light]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.pin]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.sensor]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.firmata.switch]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.geniushub]
|
||||
ignore_errors = true
|
||||
|
||||
|
@ -48,14 +48,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||
"homeassistant.components.fireservicerota.binary_sensor",
|
||||
"homeassistant.components.fireservicerota.sensor",
|
||||
"homeassistant.components.fireservicerota.switch",
|
||||
"homeassistant.components.firmata",
|
||||
"homeassistant.components.firmata.binary_sensor",
|
||||
"homeassistant.components.firmata.board",
|
||||
"homeassistant.components.firmata.entity",
|
||||
"homeassistant.components.firmata.light",
|
||||
"homeassistant.components.firmata.pin",
|
||||
"homeassistant.components.firmata.sensor",
|
||||
"homeassistant.components.firmata.switch",
|
||||
"homeassistant.components.geniushub",
|
||||
"homeassistant.components.geniushub.binary_sensor",
|
||||
"homeassistant.components.geniushub.climate",
|
||||
|
Loading…
x
Reference in New Issue
Block a user