Skip to content
Open
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
103 changes: 99 additions & 4 deletions custom_components/wuling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
UnitOfElectricCurrent,
UnitOfTime,
UnitOfPower,
UnitOfSpeed,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -99,6 +100,19 @@ def decode(self, client, payload, value):
payload[self.attr] = 0.0


class SteeringAngleSensorConv(NumberSensorConv):
def decode(self, client, payload, value):
try:
raw_value = float(value)
if 0 <= raw_value <= 2048:
payload[self.attr] = round(raw_value, 3)
elif 2048 < raw_value < 4096:
payload[self.attr] = round(raw_value - 4096, 3)
else:
payload[self.attr] = 0.0
except (ValueError, TypeError):
payload[self.attr] = 0.0


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data.setdefault(entry.entry_id, {})
Expand Down Expand Up @@ -171,6 +185,12 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
'device_class': SensorDeviceClass.DISTANCE,
'unit_of_measurement': UnitOfLength.KILOMETERS,
}),
NumberSensorConv('veh_Spd_AvgDrvn', prop='carStatus.vehSpdAvgDrvn', precision=1).with_option({
'icon': 'mdi:speedometer',
'state_class': SensorStateClass.MEASUREMENT,
'device_class':SensorDeviceClass.SPEED,
'unit_of_measurement': UnitOfSpeed.KILOMETERS_PER_HOUR,
}),
NumberSensorConv('oil_level', prop='carStatus.leftFuel').with_option({
'icon': 'mdi:water-percent',
'state_class': SensorStateClass.MEASUREMENT,
Expand All @@ -182,7 +202,37 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('battery_voltage', prop='carStatus.voltage').with_option({
NumberSensorConv('battery_temp_min', prop='carStatus.batMinTemp').with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.TEMPERATURE,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('battery_temp_max', prop='carStatus.batMaxTemp').with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.TEMPERATURE,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('invActTemp', prop='carStatus.invActTemp').with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.TEMPERATURE,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('cdj_temp', prop='carStatus.cdjTemp').with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.TEMPERATURE,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('obc_temp', prop='carStatus.obcTemp').with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.TEMPERATURE,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfTemperature.CELSIUS,
}),
NumberSensorConv('battery_voltage', prop='carStatus.voltage', precision=1).with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.VOLTAGE,
'entity_category': EntityCategory.DIAGNOSTIC,
Expand All @@ -194,10 +244,16 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': PERCENTAGE,
}),
NumberSensorConv('battery_SOH', prop='carStatus.batSOH').with_option({
'icon': 'mdi:battery-heart',
'state_class': SensorStateClass.MEASUREMENT,
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': PERCENTAGE,
}),
SensorConv('battery_status', prop='carStatus.batteryStatus').with_option({
'icon': 'mdi:battery-unknown',
}),
NumberSensorConv('small_battery_voltage', prop='carStatus.lowBatVol').with_option({
NumberSensorConv('small_battery_voltage', prop='carStatus.lowBatVol', precision=2).with_option({
'state_class': SensorStateClass.MEASUREMENT,
'device_class': SensorDeviceClass.VOLTAGE,
'entity_category': EntityCategory.DIAGNOSTIC,
Expand Down Expand Up @@ -234,6 +290,38 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
BinarySensorConv('window3_status', prop='carStatus.window3OpenStatus', parent='window_status'),
BinarySensorConv('window4_status', prop='carStatus.window4OpenStatus', parent='window_status'),

BinarySensorConv('leftTurnLight', prop='carStatus.leftTurnLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
'state_class': SensorStateClass.MEASUREMENT,
}),
BinarySensorConv('rightTurnLight', prop='carStatus.rightTurnLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
}),
BinarySensorConv('rearFogLight', prop='carStatus.rearFogLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
'parent': 'frontFogLight',
}),
BinarySensorConv('frontFogLight', prop='carStatus.frontFogLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
}),
BinarySensorConv('dipHeadLight', prop='carStatus.dipHeadLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
'parent': 'lowBeamLight',
}),
BinarySensorConv('lowBeamLight', prop='carStatus.lowBeamLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
}),
BinarySensorConv('positionLight', prop='carStatus.positionLight').with_option({
'icon': 'mdi:car-parking-lights',
'device_class': BinarySensorDeviceClass.LIGHT,
}),

BinarySensorConv('charging', prop='carStatus.charging').with_option({
'device_class': BinarySensorDeviceClass.BATTERY_CHARGING,
}),
Expand Down Expand Up @@ -347,6 +435,11 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
'entity_category': EntityCategory.DIAGNOSTIC,
'unit_of_measurement': UnitOfPressure.KPA,
}),
SteeringAngleSensorConv('strWhAng', prop='carStatus.strWhAng', precision=3).with_option({
'icon': 'mdi:steering',
'state_class': SensorStateClass.MEASUREMENT,
'device_class': None,
}),
]

@property
Expand Down Expand Up @@ -388,7 +481,9 @@ def vin_sort(self):
def model(self):
name = self.car_info.get('carTypeName', '')
model = self.car_info.get('model', '')
return f'{name} {model}'.strip()
level = self.car_info.get('level', '')
colorName = self.car_info.get('colorName', '')
return f'{name} {model} {level} {colorName}'.strip()

async def update_from_service(self, call: ServiceCall):
data = call.data
Expand Down Expand Up @@ -612,4 +707,4 @@ def update(self):

@callback
def _handle_coordinator_update(self) -> None:
self.update()
self.update()
46 changes: 46 additions & 0 deletions custom_components/wuling/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"total_mileage": {
"name": "总里程"
},
"veh_Spd_AvgDrvn": {
"name": "平均车速",
"unit": "km/h"
},
"left_mileage": {
"name": "纯电续航"
},
Expand All @@ -61,18 +65,39 @@
"battery_temp": {
"name": "电池温度"
},
"battery_temp_min": {
"name": "电池单体最低温度"
},
"battery_temp_max": {
"name": "电池单体最高温度"
},
"invActTemp": {
"name": "逆变器温度"
},
"obc_temp": {
"name": "交流充电机温度"
},
"cdj_temp": {
"name": "充电机插口温度"
},
"battery_voltage": {
"name": "电池电压"
},
"battery_health": {
"name": "电池健康"
},
"battery_SOH": {
"name": "电池SOH"
},
"battery_status": {
"name": "电池状态"
},
"small_battery_voltage": {
"name": "电瓶电压"
},
"strWhAng": {
"name": "方向盘角度"
},
"door_status": {
"name": "车门状态"
},
Expand Down Expand Up @@ -120,6 +145,27 @@
"window_status": {
"name": "车窗状态"
},
"leftTurnLight": {
"name": "左转灯"
},
"rightTurnLight": {
"name": "右转灯"
},
"rearFogLight": {
"name": "后雾灯"
},
"frontFogLight": {
"name": "前雾灯"
},
"dipHeadLight": {
"name": "dipHeadLight"
},
"lowBeamLight": {
"name": "车头灯"
},
"positionLight": {
"name": "示廓灯"
},
"charging": {
"name": "充电状态"
},
Expand Down