feat: refactor code to add more devices.

This commit is contained in:
sususweet
2025-09-24 20:56:04 +08:00
parent 51f0fcc8dc
commit b1bf76f292
8 changed files with 647 additions and 20 deletions

View File

@@ -15,7 +15,6 @@ DEVICE_MAPPING = {
"entities": {
Platform.CLIMATE: {
"thermostat": {
"name": "Thermostat",
"power": "power",
"hvac_modes": {
"off": {"power": "off"},
@@ -96,7 +95,6 @@ DEVICE_MAPPING = {
"entities": {
Platform.CLIMATE: {
"thermostat": {
"name": "Thermostat",
"power": "power",
"hvac_modes": {
"off": {"power": "off"},

View File

@@ -1,6 +1,6 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime, UnitOfArea, UnitOfVolume
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
# from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
@@ -9,8 +9,151 @@ DEVICE_MAPPING = {
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {},
Platform.SENSOR: {}
Platform.SELECT: {
"fan_level": {
"options": {
"low": {"fan_level": "low"},
"medium": {"fan_level": "medium"},
"high": {"fan_level": "high"},
"auto": {"fan_level": "auto"}
}
},
"work_mode": {
"options": {
"none": {"work_mode": "none"},
"auto": {"work_mode": "auto"},
"spot": {"work_mode": "spot"},
"edge": {"work_mode": "edge"},
"single_room": {"work_mode": "single_room"},
"custom": {"work_mode": "custom"}
}
},
"work_status": {
"options": {
"idle": {"work_status": "idle"},
"cleaning": {"work_status": "cleaning"},
"returning": {"work_status": "returning"},
"docked": {"work_status": "docked"},
"on_base": {"work_status": "on_base"},
"charging": {"work_status": "charging"},
"error": {"work_status": "error"}
}
},
"move_direction": {
"options": {
"none": {"move_direction": "none"},
"forward": {"move_direction": "forward"},
"backward": {"move_direction": "backward"},
"left": {"move_direction": "left"},
"right": {"move_direction": "right"}
}
},
"query_type": {
"options": {
"work": {"query_type": "work"},
"status": {"query_type": "status"},
"battery": {"query_type": "battery"},
"error": {"query_type": "error"}
}
},
"sub_work_status": {
"options": {
"idle": {"sub_work_status": "idle"},
"cleaning": {"sub_work_status": "cleaning"},
"charging": {"sub_work_status": "charging"},
"charge_finish": {"sub_work_status": "charge_finish"},
"error": {"sub_work_status": "error"}
}
},
"water_level": {
"options": {
"low": {"water_level": "low"},
"normal": {"water_level": "normal"},
"high": {"water_level": "high"}
}
},
"mop_status": {
"options": {
"normal": {"mop_status": "normal"},
"lack_water": {"mop_status": "lack_water"},
"full_water": {"mop_status": "full_water"}
}
},
"error_type": {
"options": {
"no_error": {"error_type": "no_error"},
"can_fix": {"error_type": "can_fix"},
"need_help": {"error_type": "need_help"}
}
},
"control_type": {
"options": {
"none": {"control_type": "none"},
"app": {"control_type": "app"},
"remote": {"control_type": "remote"},
"auto": {"control_type": "auto"}
}
}
},
Platform.BINARY_SENSOR: {
"carpet_switch": {
"device_class": BinarySensorDeviceClass.RUNNING,
},
"have_reserve_task": {
"device_class": BinarySensorDeviceClass.RUNNING,
}
},
Platform.SENSOR: {
"dust_count": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"area": {
"device_class": SensorDeviceClass.AREA,
"unit_of_measurement": UnitOfArea.SQUARE_METERS,
"state_class": SensorStateClass.MEASUREMENT
},
"voice_level": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"switch_status": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"water_station_status": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"work_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"battery_percent": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"planner_status": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"sweep_then_mop_mode_progress": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"error_desc": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"station_error_desc": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}

View File

@@ -68,37 +68,31 @@ DEVICE_MAPPING = {
},
Platform.SENSOR: {
"bright": {
"name": "亮度",
"device_class": SensorDeviceClass.ILLUMINANCE,
"unit_of_measurement": "lx",
"state_class": SensorStateClass.MEASUREMENT
},
"temperature": {
"name": "温度",
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"softwater": {
"name": "软水",
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_time": {
"name": "剩余时间",
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT
},
"air_set_hour": {
"name": "空调设置时间",
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT
},
"air_left_hour": {
"name": "空调剩余时间",
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT

View File

@@ -1,6 +1,6 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime, UnitOfElectricPotential, UnitOfVolume, UnitOfMass
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
# from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
@@ -9,8 +9,227 @@ DEVICE_MAPPING = {
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {},
Platform.SENSOR: {}
Platform.SWITCH: {
"holiday_mode": {
"device_class": SwitchDeviceClass.SWITCH,
},
"water_way": {
"device_class": SwitchDeviceClass.SWITCH,
},
"soften": {
"device_class": SwitchDeviceClass.SWITCH,
},
"leak_water_protection": {
"device_class": SwitchDeviceClass.SWITCH,
},
"cl_sterilization": {
"device_class": SwitchDeviceClass.SWITCH,
},
"micro_leak": {
"device_class": SwitchDeviceClass.SWITCH,
},
"low_salt": {
"device_class": SwitchDeviceClass.SWITCH,
},
"no_salt": {
"device_class": SwitchDeviceClass.SWITCH,
},
"low_battery": {
"device_class": SwitchDeviceClass.SWITCH,
},
"salt_level_sensor_error": {
"device_class": SwitchDeviceClass.SWITCH,
},
"flowmeter_error": {
"device_class": SwitchDeviceClass.SWITCH,
},
"leak_water": {
"device_class": SwitchDeviceClass.SWITCH,
},
"micro_leak_protection": {
"device_class": SwitchDeviceClass.SWITCH,
},
"maintenance_reminder_switch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"rsj_stand_by": {
"device_class": SwitchDeviceClass.SWITCH,
},
"regeneration": {
"device_class": SwitchDeviceClass.SWITCH,
},
"pre_regeneration": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.BINARY_SENSOR: {
"maintenance_remind": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"chlorine_sterilization_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"rtc_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
}
},
Platform.SENSOR: {
"micro_leak_protection_value": {
"device_class": SensorDeviceClass.PRESSURE,
"state_class": SensorStateClass.MEASUREMENT
},
"regeneration_current_stages": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"water_hardness": {
"device_class": SensorDeviceClass.WATER,
"state_class": SensorStateClass.MEASUREMENT
},
"timing_regeneration_hour": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT
},
"real_time_setting_hour": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT
},
"timing_regeneration_min": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"regeneration_left_seconds": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.SECONDS,
"state_class": SensorStateClass.MEASUREMENT
},
"maintenance_reminder_setting": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"mixed_water_gear": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"use_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"days_since_last_regeneration": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"velocity": {
"device_class": SensorDeviceClass.SPEED,
"state_class": SensorStateClass.MEASUREMENT
},
"supply_voltage": {
"device_class": SensorDeviceClass.VOLTAGE,
"unit_of_measurement": UnitOfElectricPotential.VOLT,
"state_class": SensorStateClass.MEASUREMENT
},
"left_salt": {
"device_class": SensorDeviceClass.WEIGHT,
"unit_of_measurement": UnitOfMass.KILOGRAMS,
"state_class": SensorStateClass.MEASUREMENT
},
"pre_regeneration_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"flushing_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"salt_setting": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"regeneration_count": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"battery_voltage": {
"device_class": SensorDeviceClass.VOLTAGE,
"unit_of_measurement": UnitOfElectricPotential.VOLT,
"state_class": SensorStateClass.MEASUREMENT
},
"error": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"days_since_last_two_regeneration": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"remind_maintenance_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"real_date_setting_year": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"real_date_setting_month": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"real_date_setting_day": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"category": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"real_time_setting_min": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"regeneration_stages": {
"device_class": SensorDeviceClass.ENUM,
"state_class": SensorStateClass.MEASUREMENT
},
"soft_available_big": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.MEASUREMENT
},
"water_consumption_big": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.MEASUREMENT
},
"water_consumption_today": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.MEASUREMENT
},
"water_consumption_average": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.MEASUREMENT
},
"salt_alarm_threshold": {
"device_class": SensorDeviceClass.WEIGHT,
"unit_of_measurement": UnitOfMass.KILOGRAMS,
"state_class": SensorStateClass.MEASUREMENT
},
"leak_water_protection_value": {
"device_class": SensorDeviceClass.PRESSURE,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}