Skip to content

Commit 241b6a0

Browse files
authored
Improve type hints in gc100 (#144308)
1 parent babc183 commit 241b6a0

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

homeassistant/components/gc100/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
"""Support for controlling Global Cache gc100."""
22

3+
from __future__ import annotations
4+
35
import gc100
46
import voluptuous as vol
57

68
from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP
79
from homeassistant.core import HomeAssistant
810
from homeassistant.helpers import config_validation as cv
911
from homeassistant.helpers.typing import ConfigType
12+
from homeassistant.util.hass_dict import HassKey
1013

1114
CONF_PORTS = "ports"
1215

1316
DEFAULT_PORT = 4998
1417
DOMAIN = "gc100"
1518

16-
DATA_GC100 = "gc100"
19+
DATA_GC100: HassKey[GC100Device] = HassKey("gc100")
1720

1821
CONFIG_SCHEMA = vol.Schema(
1922
{

homeassistant/components/gc100/binary_sensor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1515
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
1616

17-
from . import CONF_PORTS, DATA_GC100
17+
from . import CONF_PORTS, DATA_GC100, GC100Device
1818

1919
_SENSORS_SCHEMA = vol.Schema({cv.string: cv.string})
2020

@@ -31,7 +31,7 @@ def setup_platform(
3131
) -> None:
3232
"""Set up the GC100 devices."""
3333
binary_sensors = []
34-
ports = config[CONF_PORTS]
34+
ports: list[dict[str, str]] = config[CONF_PORTS]
3535
for port in ports:
3636
for port_addr, port_name in port.items():
3737
binary_sensors.append(
@@ -43,31 +43,31 @@ def setup_platform(
4343
class GC100BinarySensor(BinarySensorEntity):
4444
"""Representation of a binary sensor from GC100."""
4545

46-
def __init__(self, name, port_addr, gc100):
46+
def __init__(self, name: str, port_addr: str, gc100: GC100Device) -> None:
4747
"""Initialize the GC100 binary sensor."""
4848
self._name = name or DEVICE_DEFAULT_NAME
4949
self._port_addr = port_addr
5050
self._gc100 = gc100
51-
self._state = None
51+
self._state: bool | None = None
5252

5353
# Subscribe to be notified about state changes (PUSH)
5454
self._gc100.subscribe(self._port_addr, self.set_state)
5555

5656
@property
57-
def name(self):
57+
def name(self) -> str:
5858
"""Return the name of the sensor."""
5959
return self._name
6060

6161
@property
62-
def is_on(self):
62+
def is_on(self) -> bool | None:
6363
"""Return the state of the entity."""
6464
return self._state
6565

6666
def update(self) -> None:
6767
"""Update the sensor state."""
6868
self._gc100.read_sensor(self._port_addr, self.set_state)
6969

70-
def set_state(self, state):
70+
def set_state(self, state: int) -> None:
7171
"""Set the current state."""
7272
self._state = state == 1
7373
self.schedule_update_ha_state()

homeassistant/components/gc100/switch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1717
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
1818

19-
from . import CONF_PORTS, DATA_GC100
19+
from . import CONF_PORTS, DATA_GC100, GC100Device
2020

2121
_SWITCH_SCHEMA = vol.Schema({cv.string: cv.string})
2222

@@ -33,7 +33,7 @@ def setup_platform(
3333
) -> None:
3434
"""Set up the GC100 devices."""
3535
switches = []
36-
ports = config[CONF_PORTS]
36+
ports: list[dict[str, str]] = config[CONF_PORTS]
3737
for port in ports:
3838
for port_addr, port_name in port.items():
3939
switches.append(GC100Switch(port_name, port_addr, hass.data[DATA_GC100]))
@@ -43,20 +43,20 @@ def setup_platform(
4343
class GC100Switch(SwitchEntity):
4444
"""Represent a switch/relay from GC100."""
4545

46-
def __init__(self, name, port_addr, gc100):
46+
def __init__(self, name: str, port_addr: str, gc100: GC100Device) -> None:
4747
"""Initialize the GC100 switch."""
4848
self._name = name or DEVICE_DEFAULT_NAME
4949
self._port_addr = port_addr
5050
self._gc100 = gc100
51-
self._state = None
51+
self._state: bool | None = None
5252

5353
@property
54-
def name(self):
54+
def name(self) -> str:
5555
"""Return the name of the switch."""
5656
return self._name
5757

5858
@property
59-
def is_on(self):
59+
def is_on(self) -> bool | None:
6060
"""Return the state of the entity."""
6161
return self._state
6262

@@ -72,7 +72,7 @@ def update(self) -> None:
7272
"""Update the sensor state."""
7373
self._gc100.read_sensor(self._port_addr, self.set_state)
7474

75-
def set_state(self, state):
75+
def set_state(self, state: int) -> None:
7676
"""Set the current state."""
7777
self._state = state == 1
7878
self.schedule_update_ha_state()

0 commit comments

Comments
 (0)