Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict typing to GPSD #100030

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
21 changes: 14 additions & 7 deletions homeassistant/components/gpsd/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
import socket
from typing import Any

from gps3.agps3threaded import AGPS3mechanism
import voluptuous as vol
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -89,12 +96,12 @@ def __init__(self, hass, name, host, port):
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"
Expand All @@ -103,7 +110,7 @@ def native_value(self):
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,
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down