2025-11-14 21:14:11 +08:00
|
|
|
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
2025-12-20 12:47:21 +08:00
|
|
|
from homeassistant.const import Platform, UnitOfElectricPotential
|
2025-10-11 20:44:33 +08:00
|
|
|
from homeassistant.components.switch import SwitchDeviceClass
|
|
|
|
|
|
|
|
|
|
DEVICE_MAPPING = {
|
|
|
|
|
"default": {
|
|
|
|
|
"rationale": ["off", "on"],
|
|
|
|
|
"queries": [{}],
|
2025-12-20 12:44:16 +08:00
|
|
|
"centralized": ["lightness"],
|
2025-11-14 21:14:11 +08:00
|
|
|
"calculate": {
|
|
|
|
|
"get": [
|
|
|
|
|
{
|
|
|
|
|
"lvalue": "[b7_vbattery]",
|
2025-11-27 21:39:07 +08:00
|
|
|
"rvalue": "float([b7_vbatt] / 1000.0)"
|
2025-11-14 21:14:11 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2025-10-11 20:44:33 +08:00
|
|
|
"entities": {
|
|
|
|
|
Platform.SWITCH: {
|
|
|
|
|
"power": {
|
|
|
|
|
"device_class": SwitchDeviceClass.SWITCH,
|
|
|
|
|
},
|
|
|
|
|
"light": {
|
|
|
|
|
"device_class": SwitchDeviceClass.SWITCH,
|
|
|
|
|
},
|
|
|
|
|
"wisdom_wind": {
|
|
|
|
|
"device_class": SwitchDeviceClass.SWITCH,
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-11-14 21:14:11 +08:00
|
|
|
Platform.SENSOR: {
|
|
|
|
|
"b7_left_status": {
|
|
|
|
|
"device_class": SensorDeviceClass.ENUM,
|
|
|
|
|
"translation_key": "left_status",
|
|
|
|
|
},
|
|
|
|
|
"b7_right_status": {
|
|
|
|
|
"device_class": SensorDeviceClass.ENUM,
|
|
|
|
|
"translation_key": "right_status",
|
|
|
|
|
},
|
|
|
|
|
"b7_vbattery":{
|
|
|
|
|
"device_class": SensorDeviceClass.VOLTAGE,
|
|
|
|
|
"unit_of_measurement": UnitOfElectricPotential.VOLT,
|
|
|
|
|
"state_class": SensorStateClass.MEASUREMENT,
|
|
|
|
|
"translation_key": "battery_voltage",
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-12-20 12:44:16 +08:00
|
|
|
Platform.BUTTON: {
|
|
|
|
|
"left_stove_off": {
|
|
|
|
|
"command": {"electronic_control_version": 2, "type": "b7", "b7_work_burner_control": 1,
|
|
|
|
|
"b7_function_control": 1},
|
|
|
|
|
},
|
|
|
|
|
"right_stove_off": {
|
|
|
|
|
"command": {"electronic_control_version": 2, "type": "b7", "b7_work_burner_control": 2,
|
|
|
|
|
"b7_function_control": 1},
|
|
|
|
|
},
|
|
|
|
|
"middle_stove_off": {
|
|
|
|
|
"command": {"electronic_control_version": 2, "type": "b7", "b7_work_burner_control": 3,
|
|
|
|
|
"b7_function_control": 1},
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-10-11 20:44:33 +08:00
|
|
|
Platform.SELECT: {
|
|
|
|
|
"wind_pressure": {
|
|
|
|
|
"options": {
|
|
|
|
|
"off": {"wind_pressure": "0"},
|
|
|
|
|
"low": {"wind_pressure": "1"},
|
|
|
|
|
"medium": {"wind_pressure": "2"},
|
|
|
|
|
"high": {"wind_pressure": "3"},
|
|
|
|
|
"extreme": {"wind_pressure": "4"},
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-11-14 21:14:11 +08:00
|
|
|
"gear": {
|
|
|
|
|
"options": {
|
|
|
|
|
"off": {"gear": 0},
|
|
|
|
|
"low": {"gear": 1},
|
|
|
|
|
"medium": {"gear": 2},
|
|
|
|
|
"high": {"gear": 3},
|
|
|
|
|
"extreme": {"gear": 4},
|
|
|
|
|
}
|
|
|
|
|
},
|
feat: add command template support for device control
- Add command field support to MideaNumberEntity and MideaSelectEntity
- Command templates allow defining fixed parameters in configuration
- Options/values are merged with command template before sending to device
- Backward compatible - existing configurations continue to work
Examples in device_mapping:
1. For NUMBER platform - brightness control with protocol template:
```yaml
Platform.NUMBER: {
"lightness": {
"min": 10,
"max": 100,
"step": 5,
"command": {
"electronic_control_version": 2,
"type": "b6",
"b6_action": "setting",
"setting": "light",
"lightness": "{value}" # {value} placeholder for actual number value
}
}
}
2.For SELECT platform - gesture selection with protocol template:
```yaml
Platform.SELECT: {
"gesture": {
"options": {
"off": {"gesture": "off"},
"on": {"gesture": "on"}
},
"command": { # Protocol template for gesture control
"electronic_control_version": 2,
"type": "b6",
"b6_action": "setting",
"setting": "gesture"
# {gesture} value from options will be merged automatically
}
}
}
2026-01-06 22:06:07 +08:00
|
|
|
"light": {
|
|
|
|
|
"options": {
|
|
|
|
|
"off": {"light": "off"},
|
|
|
|
|
"on": {"light": "on"}
|
|
|
|
|
},
|
|
|
|
|
"command": {
|
|
|
|
|
"electronic_control_version": 2,
|
|
|
|
|
"type": "b6",
|
|
|
|
|
"b6_action": "setting",
|
|
|
|
|
"setting": "light"
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-11 20:44:33 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|