From ad9efab16a025a45bb01e52b8b6ea81da55f831f Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 16 Jan 2026 09:46:53 +0100 Subject: [PATCH] Improve type hints in concord232 (#161045) --- .../concord232/alarm_control_panel.py | 14 ++++---- .../components/concord232/binary_sensor.py | 34 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/concord232/alarm_control_panel.py b/homeassistant/components/concord232/alarm_control_panel.py index 61cf2aebb31..f4498c43ab6 100644 --- a/homeassistant/components/concord232/alarm_control_panel.py +++ b/homeassistant/components/concord232/alarm_control_panel.py @@ -49,11 +49,11 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Concord232 alarm control panel platform.""" - name = config[CONF_NAME] - code = config.get(CONF_CODE) - mode = config[CONF_MODE] - host = config[CONF_HOST] - port = config[CONF_PORT] + name: str = config[CONF_NAME] + code: str | None = config.get(CONF_CODE) + mode: str = config[CONF_MODE] + host: str = config[CONF_HOST] + port: int = config[CONF_PORT] url = f"http://{host}:{port}" @@ -72,7 +72,7 @@ class Concord232Alarm(AlarmControlPanelEntity): | AlarmControlPanelEntityFeature.ARM_AWAY ) - def __init__(self, url, name, code, mode): + def __init__(self, url: str, name: str, code: str | None, mode: str) -> None: """Initialize the Concord232 alarm panel.""" self._attr_name = name @@ -125,7 +125,7 @@ class Concord232Alarm(AlarmControlPanelEntity): return self._alarm.arm("away") - def _validate_code(self, code, state): + def _validate_code(self, code: str | None, state: AlarmControlPanelState) -> bool: """Validate given code.""" if self._code is None: return True diff --git a/homeassistant/components/concord232/binary_sensor.py b/homeassistant/components/concord232/binary_sensor.py index 4eee5bd2d47..cc4d3bb92bd 100644 --- a/homeassistant/components/concord232/binary_sensor.py +++ b/homeassistant/components/concord232/binary_sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations import datetime import logging +from typing import Any from concord232 import client as concord232_client import requests @@ -29,8 +30,7 @@ CONF_ZONE_TYPES = "zone_types" DEFAULT_HOST = "localhost" DEFAULT_NAME = "Alarm" -DEFAULT_PORT = "5007" -DEFAULT_SSL = False +DEFAULT_PORT = 5007 SCAN_INTERVAL = datetime.timedelta(seconds=10) @@ -56,10 +56,10 @@ def setup_platform( ) -> None: """Set up the Concord232 binary sensor platform.""" - host = config[CONF_HOST] - port = config[CONF_PORT] - exclude = config[CONF_EXCLUDE_ZONES] - zone_types = config[CONF_ZONE_TYPES] + host: str = config[CONF_HOST] + port: int = config[CONF_PORT] + exclude: list[int] = config[CONF_EXCLUDE_ZONES] + zone_types: dict[int, BinarySensorDeviceClass] = config[CONF_ZONE_TYPES] sensors = [] try: @@ -84,7 +84,6 @@ def setup_platform( if zone["number"] not in exclude: sensors.append( Concord232ZoneSensor( - hass, client, zone, zone_types.get(zone["number"], get_opening_type(zone)), @@ -110,26 +109,25 @@ def get_opening_type(zone): class Concord232ZoneSensor(BinarySensorEntity): """Representation of a Concord232 zone as a sensor.""" - def __init__(self, hass, client, zone, zone_type): + def __init__( + self, + client: concord232_client.Client, + zone: dict[str, Any], + zone_type: BinarySensorDeviceClass, + ) -> None: """Initialize the Concord232 binary sensor.""" - self._hass = hass self._client = client self._zone = zone self._number = zone["number"] - self._zone_type = zone_type + self._attr_device_class = zone_type @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor, from DEVICE_CLASSES.""" - return self._zone_type - - @property - def name(self): + def name(self) -> str: """Return the name of the binary sensor.""" return self._zone["name"] @property - def is_on(self): + def is_on(self) -> bool: """Return true if the binary sensor is on.""" # True means "faulted" or "open" or "abnormal state" return bool(self._zone["state"] != "Normal") @@ -145,5 +143,5 @@ class Concord232ZoneSensor(BinarySensorEntity): if hasattr(self._client, "zones"): self._zone = next( - (x for x in self._client.zones if x["number"] == self._number), None + x for x in self._client.zones if x["number"] == self._number )