Add GPSd satellites sensors (#137320)
parent
09483d2cef
commit
15bc29f8ca
|
@ -16,6 +16,12 @@
|
||||||
},
|
},
|
||||||
"elevation": {
|
"elevation": {
|
||||||
"default": "mdi:arrow-up-down"
|
"default": "mdi:arrow-up-down"
|
||||||
|
},
|
||||||
|
"total_satellites": {
|
||||||
|
"default": "mdi:satellite-variant"
|
||||||
|
},
|
||||||
|
"used_satellites": {
|
||||||
|
"default": "mdi:satellite-variant"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_LATITUDE,
|
ATTR_LATITUDE,
|
||||||
|
@ -39,12 +40,31 @@ ATTR_CLIMB = "climb"
|
||||||
ATTR_ELEVATION = "elevation"
|
ATTR_ELEVATION = "elevation"
|
||||||
ATTR_GPS_TIME = "gps_time"
|
ATTR_GPS_TIME = "gps_time"
|
||||||
ATTR_SPEED = "speed"
|
ATTR_SPEED = "speed"
|
||||||
|
ATTR_TOTAL_SATELLITES = "total_satellites"
|
||||||
|
ATTR_USED_SATELLITES = "used_satellites"
|
||||||
|
|
||||||
DEFAULT_NAME = "GPS"
|
DEFAULT_NAME = "GPS"
|
||||||
|
|
||||||
_MODE_VALUES = {2: "2d_fix", 3: "3d_fix"}
|
_MODE_VALUES = {2: "2d_fix", 3: "3d_fix"}
|
||||||
|
|
||||||
|
|
||||||
|
def count_total_satellites_fn(agps_thread: AGPS3mechanism) -> int | None:
|
||||||
|
"""Count the number of total satellites."""
|
||||||
|
satellites = agps_thread.data_stream.satellites
|
||||||
|
return None if satellites == "n/a" else len(satellites)
|
||||||
|
|
||||||
|
|
||||||
|
def count_used_satellites_fn(agps_thread: AGPS3mechanism) -> int | None:
|
||||||
|
"""Count the number of used satellites."""
|
||||||
|
satellites = agps_thread.data_stream.satellites
|
||||||
|
if satellites == "n/a":
|
||||||
|
return None
|
||||||
|
|
||||||
|
return sum(
|
||||||
|
1 for sat in satellites if isinstance(sat, dict) and sat.get("used", False)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class GpsdSensorDescription(SensorEntityDescription):
|
class GpsdSensorDescription(SensorEntityDescription):
|
||||||
"""Class describing GPSD sensor entities."""
|
"""Class describing GPSD sensor entities."""
|
||||||
|
@ -116,6 +136,22 @@ SENSOR_TYPES: tuple[GpsdSensorDescription, ...] = (
|
||||||
suggested_display_precision=2,
|
suggested_display_precision=2,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
|
GpsdSensorDescription(
|
||||||
|
key=ATTR_TOTAL_SATELLITES,
|
||||||
|
translation_key=ATTR_TOTAL_SATELLITES,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=count_total_satellites_fn,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
GpsdSensorDescription(
|
||||||
|
key=ATTR_USED_SATELLITES,
|
||||||
|
translation_key=ATTR_USED_SATELLITES,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=count_used_satellites_fn,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,14 @@
|
||||||
},
|
},
|
||||||
"mode": { "name": "[%key:common::config_flow::data::mode%]" }
|
"mode": { "name": "[%key:common::config_flow::data::mode%]" }
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"total_satellites": {
|
||||||
|
"name": "Total satellites",
|
||||||
|
"unit_of_measurement": "satellites"
|
||||||
|
},
|
||||||
|
"used_satellites": {
|
||||||
|
"name": "Used satellites",
|
||||||
|
"unit_of_measurement": "satellites"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue