Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Add state attribute translations
Browse files Browse the repository at this point in the history
  • Loading branch information
dscao authored Apr 6, 2023
1 parent 7f9ab0b commit 5cb41a7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 13 deletions.
4 changes: 2 additions & 2 deletions custom_components/gooddriver/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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"


18 changes: 9 additions & 9 deletions custom_components/gooddriver/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -124,18 +125,17 @@ def longitude(self):

@property
def location_accuracy(self):
return 10
return 0

@property
def state_attributes(self):
attrs = super(gooddriverEntity, self).state_attributes
#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"]
Expand All @@ -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"]]
65 changes: 64 additions & 1 deletion custom_components/gooddriver/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
}
}
65 changes: 64 additions & 1 deletion custom_components/gooddriver/translations/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "路由器"
}
}
}
}
}
}
}

0 comments on commit 5cb41a7

Please sign in to comment.