From 5cb41a74b6b59743051dd6dc8af5a7e2be5f8fe0 Mon Sep 17 00:00:00 2001 From: dscao Date: Fri, 7 Apr 2023 01:12:48 +0800 Subject: [PATCH] Add state attribute translations --- custom_components/gooddriver/const.py | 4 +- .../gooddriver/device_tracker.py | 18 ++--- .../gooddriver/translations/en.json | 65 ++++++++++++++++++- .../gooddriver/translations/zh-Hans.json | 65 ++++++++++++++++++- 4 files changed, 139 insertions(+), 13 deletions(-) diff --git a/custom_components/gooddriver/const.py b/custom_components/gooddriver/const.py index 4933e5c..0e94c3d 100644 --- a/custom_components/gooddriver/const.py +++ b/custom_components/gooddriver/const.py @@ -10,7 +10,7 @@ "config_flow.py", "translations/en.json", ] -VERSION = "2022.5.16" +VERSION = "2023.4.1" ISSUE_URL = "https://github.com/dscao/gooddriver/issues" STARTUP = """ @@ -49,7 +49,7 @@ ATTR_RUNORSTOP = "runorstop" ATTR_LASTSTOPTIME = "laststoptime" ATTR_UPDATE_TIME = "update_time" -ATTR_QUERYTIME = "querytime" +ATTR_QUERYTIME = "query_time" ATTR_PARKING_TIME = "parking_time" diff --git a/custom_components/gooddriver/device_tracker.py b/custom_components/gooddriver/device_tracker.py index 8e7a657..4d88593 100644 --- a/custom_components/gooddriver/device_tracker.py +++ b/custom_components/gooddriver/device_tracker.py @@ -58,7 +58,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class gooddriverEntity(TrackerEntity): """Representation of a tracker condition.""" _attr_has_entity_name = True - _attr_name = None + # _attr_name = None + _attr_translation_key = "gooddriver_device_tracker" def __init__(self, name, gps_conver, attr_show, coordinator): self.coordinator = coordinator @@ -73,9 +74,9 @@ def __init__(self, name, gps_conver, attr_show, coordinator): else: self._coords = [self.coordinator.data["thislon"], self.coordinator.data["thislat"]] - @property - def name(self): - return self._name + # @property + # def name(self): + # return self._name @property @@ -124,7 +125,7 @@ def longitude(self): @property def location_accuracy(self): - return 10 + return 0 @property def state_attributes(self): @@ -132,10 +133,9 @@ def state_attributes(self): #data = self.coordinator.data.get("result") data = self.coordinator.data if data: - attrs["speed"] = data["speed"] - attrs["speed"] = data["speed"] + attrs[ATTR_SPEED] = data["speed"] attrs[ATTR_STATUS] = data["status"] - attrs["updatetime"] = data["updatetime"] + attrs[ATTR_UPDATE_TIME] = data["updatetime"] attrs[ATTR_QUERYTIME] = data["querytime"] if self._attr_show == True: attrs[ATTR_RUNORSTOP] = data["runorstop"] @@ -156,4 +156,4 @@ async def async_update(self): if self._gps_conver == True: self._coords = gcj02towgs84(self.coordinator.data["thislon"], self.coordinator.data["thislat"]) else: - self._coords = [self.coordinator.data["thislon"], self.coordinator.data["thislat"]] + self._coords = [self.coordinator.data["thislon"], self.coordinator.data["thislat"]] \ No newline at end of file diff --git a/custom_components/gooddriver/translations/en.json b/custom_components/gooddriver/translations/en.json index 9452934..1ea2f3c 100644 --- a/custom_components/gooddriver/translations/en.json +++ b/custom_components/gooddriver/translations/en.json @@ -31,5 +31,68 @@ "description": "Set Entity Attributes" } } - } + }, + "entity": { + "device_tracker": { + "gooddriver_device_tracker": { + "name": "gooddriver", + "state_attributes": { + "speed": { + "name": "Speed" + }, + "course": { + "name": "Course" + }, + "status": { + "name": "status", + "state": { + "车辆点火": "Vehicle ignition", + "车辆熄火": "Vehicle stalled", + "未知": "Unknown" + } + }, + "update_time": { + "name": "update time" + }, + "query_time": { + "name": "query time" + }, + "runorstop": { + "name": "run or stop", + "state": { + "静止": "Stopped", + "运动": "Running" + } + }, + "laststoptime": { + "name": "laststoptime" + }, + "parking_time": { + "name": "parking time" + }, + "battery": { + "name": "Battery" + }, + "gps_accuracy": { + "name": "GPS accuracy" + }, + "latitude": { + "name": "Latitude" + }, + "longitude": { + "name": "Longitude" + }, + "source_type": { + "name": "Source", + "state": { + "bluetooth_le": "Bluetooth LE", + "bluetooth": "Bluetooth", + "gps": "GPS", + "router": "Router" + } + } + } + } + } + } } \ No newline at end of file diff --git a/custom_components/gooddriver/translations/zh-Hans.json b/custom_components/gooddriver/translations/zh-Hans.json index 1bac425..99cd4ba 100644 --- a/custom_components/gooddriver/translations/zh-Hans.json +++ b/custom_components/gooddriver/translations/zh-Hans.json @@ -31,5 +31,68 @@ "description": "设置实体属性是否显示" } } - } + }, + "entity": { + "device_tracker": { + "gooddriver_device_tracker": { + "name": "优驾盒子", + "state_attributes": { + "speed": { + "name": "当前车速" + }, + "course": { + "name": "行车方向" + }, + "status": { + "name": "当前状态", + "state": { + "车辆点火": "车辆点火", + "车辆熄火": "车辆熄火", + "未知": "未知" + } + }, + "update_time": { + "name": "更新时间" + }, + "query_time": { + "name": "查询时间" + }, + "runorstop": { + "name": "运动状态", + "state": { + "静止": "静止", + "运动": "运动" + } + }, + "laststoptime": { + "name": "上次停止时间" + }, + "parking_time": { + "name": "停车时长" + }, + "battery": { + "name": "电池电量" + }, + "gps_accuracy": { + "name": "GPS精度" + }, + "latitude": { + "name": "纬度" + }, + "longitude": { + "name": "经度" + }, + "source_type": { + "name": "数据源", + "state": { + "bluetooth_le": "低功耗蓝牙", + "bluetooth": "蓝牙", + "gps": "GPS定位", + "router": "路由器" + } + } + } + } + } + } } \ No newline at end of file