mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add translations to GPSd (#108600)
* Add config flow to GPSD * Add translations to GPSd * Add device class * Apply feedback for unique_id and translation_key
This commit is contained in:
parent
3ce4e53b32
commit
45f0e08395
@ -11,7 +11,11 @@ from gps3.agps3threaded import (
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_LATITUDE,
|
||||
@ -98,6 +102,9 @@ class GpsdSensor(SensorEntity):
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
_attr_translation_key = "mode"
|
||||
_attr_device_class = SensorDeviceClass.ENUM
|
||||
_attr_options = ["2d_fix", "3d_fix"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -110,7 +117,7 @@ class GpsdSensor(SensorEntity):
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
)
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_unique_id = f"{unique_id}-mode"
|
||||
|
||||
self.agps_thread = AGPS3mechanism()
|
||||
self.agps_thread.stream_data(host=host, port=port)
|
||||
@ -120,9 +127,9 @@ class GpsdSensor(SensorEntity):
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of GPSD."""
|
||||
if self.agps_thread.data_stream.mode == 3:
|
||||
return "3D Fix"
|
||||
return "3d_fix"
|
||||
if self.agps_thread.data_stream.mode == 2:
|
||||
return "2D Fix"
|
||||
return "2d_fix"
|
||||
return None
|
||||
|
||||
@property
|
||||
|
@ -15,5 +15,26 @@
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"mode": {
|
||||
"state": {
|
||||
"2d_fix": "2D Fix",
|
||||
"3d_fix": "3D Fix"
|
||||
},
|
||||
"state_attributes": {
|
||||
"latitude": { "name": "[%key:common::config_flow::data::latitude%]" },
|
||||
"longitude": {
|
||||
"name": "[%key:common::config_flow::data::longitude%]"
|
||||
},
|
||||
"elevation": { "name": "Elevation" },
|
||||
"gps_time": { "name": "Time" },
|
||||
"speed": { "name": "Speed" },
|
||||
"climb": { "name": "Climb" },
|
||||
"mode": { "name": "Mode" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user