Update tuya translation for reverse energy sensor (#149317)

This commit is contained in:
yufeng
2025-08-07 23:08:57 +08:00
committed by GitHub
parent d778afe61a
commit ff9e2a8f1e
5 changed files with 552 additions and 1 deletions

View File

@@ -1334,7 +1334,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
), ),
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
key=DPCode.REVERSE_ENERGY_TOTAL, key=DPCode.REVERSE_ENERGY_TOTAL,
translation_key="total_energy", translation_key="total_production",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),

View File

@@ -489,6 +489,11 @@ DEVICE_MOCKS = {
Platform.NUMBER, Platform.NUMBER,
Platform.SENSOR, Platform.SENSOR,
], ],
"zndb_4ggkyflayu1h1ho9": [
# https://github.com/home-assistant/core/pull/149317
Platform.SENSOR,
Platform.SWITCH,
],
"zndb_ze8faryrxr0glqnn": [ "zndb_ze8faryrxr0glqnn": [
# https://github.com/home-assistant/core/issues/138372 # https://github.com/home-assistant/core/issues/138372
Platform.SENSOR, Platform.SENSOR,

View File

@@ -0,0 +1,218 @@
{
"endpoint": "https://apigw.tuyacn.com",
"terminal_id": "1753864737914eTkTk2",
"mqtt_connected": true,
"disabled_by": null,
"disabled_polling": false,
"id": "6c0887b46a2eaf56e0ui7d",
"name": "XOCA-DAC212XC V2-S1",
"category": "zndb",
"product_id": "4ggkyflayu1h1ho9",
"product_name": "XOCA-DAC212XC V2-S1",
"online": true,
"sub": false,
"time_zone": "+08:00",
"active_time": "2025-07-07T10:32:35+00:00",
"create_time": "2025-07-07T10:32:35+00:00",
"update_time": "2025-07-07T10:32:35+00:00",
"function": {
"frozen_time_set": {
"type": "Json",
"value": {}
},
"switch_prepayment": {
"type": "Boolean",
"value": {}
},
"clear_energy": {
"type": "Boolean",
"value": {}
},
"switch": {
"type": "Boolean",
"value": {}
},
"alarm_set_2": {
"type": "Json",
"value": {}
},
"event_clear": {
"type": "Boolean",
"value": {}
},
"price_set": {
"type": "Raw",
"value": {}
}
},
"status_range": {
"forward_energy_total": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"reverse_energy_total": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"phase_a": {
"type": "Json",
"value": {}
},
"fault": {
"type": "Bitmap",
"value": {
"label": [
"ov_cr",
"unbalance_alarm",
"ov_vol",
"undervoltage_alarm",
"miss_phase_alarm",
"outage_alarm",
"magnetism_alarm",
"terminal_alarm",
"cover_alarm",
"credit_alarm",
"no_balance_alarm",
"battery_alarm",
"meter_hardware_alarm",
"overdraft_unlim",
"arrear_outage",
"overdraft_use",
"pf_abnormal",
"ov_pwr"
]
}
},
"frozen_time_set": {
"type": "Json",
"value": {}
},
"switch_prepayment": {
"type": "Boolean",
"value": {}
},
"clear_energy": {
"type": "Boolean",
"value": {}
},
"switch": {
"type": "Boolean",
"value": {}
},
"alarm_set_2": {
"type": "Json",
"value": {}
},
"meter_id": {
"type": "String",
"value": {
"maxlen": 255
}
},
"event_clear": {
"type": "Boolean",
"value": {}
},
"forward_energy_t1": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"forward_energy_t2": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"forward_energy_t3": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"forward_energy_t4": {
"type": "Integer",
"value": {
"unit": "kW\u00b7h",
"min": 0,
"max": 99999999,
"scale": 2,
"step": 1
}
},
"price_set": {
"type": "Raw",
"value": {}
},
"online_state": {
"type": "Enum",
"value": {
"range": ["offline", "online"]
}
},
"supply_frequency": {
"type": "Integer",
"value": {
"unit": "Hz",
"min": 0,
"max": 9999,
"scale": 2,
"step": 1
}
}
},
"status": {
"forward_energy_total": 120,
"reverse_energy_total": 80,
"phase_a": {
"electricCurrent": 599.552,
"power": 6.912,
"voltage": 52.7
},
"fault": 0,
"frozen_time_set": {
"day": 158,
"hour": 233
},
"switch_prepayment": false,
"clear_energy": false,
"switch": true,
"alarm_set_2": [],
"meter_id": "",
"event_clear": false,
"forward_energy_t1": 0,
"forward_energy_t2": 0,
"forward_energy_t3": 0,
"forward_energy_t4": 0,
"price_set": "",
"online_state": "offline",
"supply_frequency": 0
},
"set_up": true,
"support_local": true
}

View File

@@ -4941,6 +4941,286 @@
'state': 'upper_alarm', 'state': 'upper_alarm',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_current-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_current',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.CURRENT: 'current'>,
'original_icon': None,
'original_name': 'Phase A current',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'phase_a_current',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dphase_aelectriccurrent',
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_current-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'XOCA-DAC212XC V2-S1 Phase A current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_current',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '599.552',
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_power-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_power',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Phase A power',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'phase_a_power',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dphase_apower',
'unit_of_measurement': <UnitOfPower.KILO_WATT: 'kW'>,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_power-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'XOCA-DAC212XC V2-S1 Phase A power',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.KILO_WATT: 'kW'>,
}),
'context': <ANY>,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_power',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '6.912',
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_voltage-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_voltage',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 0,
}),
}),
'original_device_class': <SensorDeviceClass.VOLTAGE: 'voltage'>,
'original_icon': None,
'original_name': 'Phase A voltage',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'phase_a_voltage',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dphase_avoltage',
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_phase_a_voltage-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'voltage',
'friendly_name': 'XOCA-DAC212XC V2-S1 Phase A voltage',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
}),
'context': <ANY>,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_phase_a_voltage',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '52.7',
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_total_energy-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_total_energy',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Total energy',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'total_energy',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dforward_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_total_energy-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'XOCA-DAC212XC V2-S1 Total energy',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_total_energy',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1.2',
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_total_production-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_total_production',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Total production',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'total_production',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dreverse_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][sensor.xoca_dac212xc_v2_s1_total_production-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'XOCA-DAC212XC V2-S1 Total production',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.xoca_dac212xc_v2_s1_total_production',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.8',
})
# ---
# name: test_platform_setup_and_discovery[zndb_ze8faryrxr0glqnn][sensor.meter_phase_a_current-entry] # name: test_platform_setup_and_discovery[zndb_ze8faryrxr0glqnn][sensor.meter_phase_a_current-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@@ -3579,3 +3579,51 @@
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][switch.xoca_dac212xc_v2_s1_switch-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.xoca_dac212xc_v2_s1_switch',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Switch',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'switch',
'unique_id': 'tuya.6c0887b46a2eaf56e0ui7dswitch',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[zndb_4ggkyflayu1h1ho9][switch.xoca_dac212xc_v2_s1_switch-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'XOCA-DAC212XC V2-S1 Switch',
}),
'context': <ANY>,
'entity_id': 'switch.xoca_dac212xc_v2_s1_switch',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---