Add strict typing to GPSD (#100030)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Jan Rieger 2023-09-12 22:21:58 +02:00 committed by GitHub
parent e3837cd1e0
commit f2fac40019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -141,6 +141,7 @@ homeassistant.components.glances.*
homeassistant.components.goalzero.*
homeassistant.components.google.*
homeassistant.components.google_sheets.*
homeassistant.components.gpsd.*
homeassistant.components.greeneye_monitor.*
homeassistant.components.group.*
homeassistant.components.guardian.*

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import logging
import socket
from typing import Any
from gps3.agps3threaded import AGPS3mechanism
import voluptuous as vol
@ -48,9 +49,9 @@ def setup_platform(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the GPSD component."""
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
name = config[CONF_NAME]
host = config[CONF_HOST]
port = config[CONF_PORT]
# Will hopefully be possible with the next gps3 update
# https://github.com/wadda/gps3/issues/11
@ -77,7 +78,13 @@ def setup_platform(
class GpsdSensor(SensorEntity):
"""Representation of a GPS receiver available via GPSD."""
def __init__(self, hass, name, host, port):
def __init__(
self,
hass: HomeAssistant,
name: str,
host: str,
port: int,
) -> None:
"""Initialize the GPSD sensor."""
self.hass = hass
self._name = name
@ -89,12 +96,12 @@ class GpsdSensor(SensorEntity):
self.agps_thread.run_thread()
@property
def name(self):
def name(self) -> str:
"""Return the name."""
return self._name
@property
def native_value(self):
def native_value(self) -> str | None:
"""Return the state of GPSD."""
if self.agps_thread.data_stream.mode == 3:
return "3D Fix"
@ -103,7 +110,7 @@ class GpsdSensor(SensorEntity):
return None
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the GPS."""
return {
ATTR_LATITUDE: self.agps_thread.data_stream.lat,

View File

@ -1172,6 +1172,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.gpsd.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.greeneye_monitor.*]
check_untyped_defs = true
disallow_incomplete_defs = true