mirror of
https://github.com/home-assistant/core
synced 2024-10-01 19:08:29 +00:00
Add strict typing to GPSD (#100030)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
e3837cd1e0
commit
f2fac40019
|
@ -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.*
|
||||
|
|
|
@ -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,
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue