test_pc321ty_energy_meter.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. """Tests for the PC321-TY Power Clamp Energy meter"""
  2. from homeassistant.components.sensor import (
  3. STATE_CLASS_MEASUREMENT,
  4. STATE_CLASS_TOTAL_INCREASING,
  5. SensorDeviceClass,
  6. )
  7. from homeassistant.const import (
  8. UnitOfElectricCurrent,
  9. UnitOfElectricPotential,
  10. UnitOfEnergy,
  11. UnitOfFrequency,
  12. UnitOfPower,
  13. UnitOfTemperature,
  14. )
  15. from ..const import PC321TY_POWERCLAMP_PAYLOAD
  16. from ..mixins.sensor import MultiSensorTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. VOLTAGE1_DP = "101"
  19. CURRENT1_DP = "102"
  20. POWER1_DP = "103"
  21. PFACTOR1_DP = "104"
  22. ENERGY1_DP = "106"
  23. VOLTAGE2_DP = "111"
  24. CURRENT2_DP = "112"
  25. POWER2_DP = "113"
  26. PFACTOR2_DP = "114"
  27. ENERGY2_DP = "116"
  28. VOLTAGE3_DP = "121"
  29. CURRENT3_DP = "122"
  30. POWER3_DP = "123"
  31. PFACTOR3_DP = "124"
  32. ENERGY3_DP = "126"
  33. TOTALENERGY_DP = "131"
  34. TOTALCURRENT_DP = "132"
  35. TOTALPOWER_DP = "133"
  36. FREQUENCY_DP = "135"
  37. TEMPERATURE_DP = "136"
  38. class TestPC321TYPowerClamp(MultiSensorTests, TuyaDeviceTestCase):
  39. __test__ = True
  40. def setUp(self):
  41. self.setUpForConfig(
  42. "pc321ty_energy_meter.yaml",
  43. PC321TY_POWERCLAMP_PAYLOAD,
  44. )
  45. self.setUpMultiSensors(
  46. [
  47. {
  48. "dps": TOTALENERGY_DP,
  49. "name": "sensor_energy",
  50. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  51. "device_class": SensorDeviceClass.ENERGY,
  52. "state_class": STATE_CLASS_TOTAL_INCREASING,
  53. "testdata": (12345, 123.45),
  54. },
  55. {
  56. "dps": VOLTAGE1_DP,
  57. "name": "sensor_voltage_a",
  58. "unit": UnitOfElectricPotential.VOLT,
  59. "device_class": SensorDeviceClass.VOLTAGE,
  60. "state_class": STATE_CLASS_MEASUREMENT,
  61. "testdata": (2348, 234.8),
  62. },
  63. {
  64. "dps": CURRENT1_DP,
  65. "name": "sensor_current_a",
  66. "unit": UnitOfElectricCurrent.AMPERE,
  67. "device_class": SensorDeviceClass.CURRENT,
  68. "state_class": STATE_CLASS_MEASUREMENT,
  69. "testdata": (4567, 4.567),
  70. },
  71. {
  72. "dps": POWER1_DP,
  73. "name": "sensor_power_a",
  74. "unit": UnitOfPower.WATT,
  75. "state_class": STATE_CLASS_MEASUREMENT,
  76. "device_class": SensorDeviceClass.POWER,
  77. },
  78. {
  79. "dps": PFACTOR1_DP,
  80. "name": "sensor_power_factor_a",
  81. "device_class": SensorDeviceClass.POWER_FACTOR,
  82. "state_class": STATE_CLASS_MEASUREMENT,
  83. "testdata": (5000, 50.00),
  84. },
  85. {
  86. "dps": ENERGY1_DP,
  87. "name": "sensor_energy_a",
  88. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  89. "testdata": (12345, 123.45),
  90. },
  91. {
  92. "dps": VOLTAGE2_DP,
  93. "name": "sensor_voltage_b",
  94. "unit": UnitOfElectricPotential.VOLT,
  95. "device_class": SensorDeviceClass.VOLTAGE,
  96. "state_class": STATE_CLASS_MEASUREMENT,
  97. "testdata": (2348, 234.8),
  98. },
  99. {
  100. "dps": CURRENT2_DP,
  101. "name": "sensor_current_b",
  102. "unit": UnitOfElectricCurrent.AMPERE,
  103. "device_class": SensorDeviceClass.CURRENT,
  104. "state_class": STATE_CLASS_MEASUREMENT,
  105. "testdata": (4567, 4.567),
  106. },
  107. {
  108. "dps": POWER2_DP,
  109. "name": "sensor_power_b",
  110. "unit": UnitOfPower.WATT,
  111. "device_class": SensorDeviceClass.POWER,
  112. "state_class": STATE_CLASS_MEASUREMENT,
  113. },
  114. {
  115. "dps": PFACTOR2_DP,
  116. "name": "sensor_power_factor_b",
  117. "device_class": SensorDeviceClass.POWER_FACTOR,
  118. "state_class": STATE_CLASS_MEASUREMENT,
  119. "testdata": (5000, 50.00),
  120. },
  121. {
  122. "dps": ENERGY2_DP,
  123. "name": "sensor_energy_b",
  124. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  125. "testdata": (12345, 123.45),
  126. },
  127. {
  128. "dps": VOLTAGE3_DP,
  129. "name": "sensor_voltage_c",
  130. "unit": UnitOfElectricPotential.VOLT,
  131. "device_class": SensorDeviceClass.VOLTAGE,
  132. "state_class": STATE_CLASS_MEASUREMENT,
  133. "testdata": (2348, 234.8),
  134. },
  135. {
  136. "dps": CURRENT3_DP,
  137. "name": "sensor_current_c",
  138. "unit": UnitOfElectricCurrent.AMPERE,
  139. "device_class": SensorDeviceClass.CURRENT,
  140. "state_class": STATE_CLASS_MEASUREMENT,
  141. "testdata": (4567, 4.567),
  142. },
  143. {
  144. "dps": POWER3_DP,
  145. "name": "sensor_power_c",
  146. "unit": UnitOfPower.WATT,
  147. "state_class": STATE_CLASS_MEASUREMENT,
  148. "device_class": SensorDeviceClass.POWER,
  149. },
  150. {
  151. "dps": PFACTOR3_DP,
  152. "name": "sensor_power_factor_c",
  153. "device_class": SensorDeviceClass.POWER_FACTOR,
  154. "state_class": STATE_CLASS_MEASUREMENT,
  155. "testdata": (5000, 50.00),
  156. },
  157. {
  158. "dps": ENERGY3_DP,
  159. "name": "sensor_energy_c",
  160. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  161. "testdata": (12345, 123.45),
  162. },
  163. {
  164. "dps": TOTALCURRENT_DP,
  165. "name": "sensor_total_current",
  166. "unit": UnitOfElectricCurrent.AMPERE,
  167. "device_class": SensorDeviceClass.CURRENT,
  168. "state_class": STATE_CLASS_MEASUREMENT,
  169. "testdata": (12345, 12.345),
  170. },
  171. {
  172. "dps": TOTALPOWER_DP,
  173. "name": "sensor_total_active_power",
  174. "unit": UnitOfPower.WATT,
  175. "state_class": STATE_CLASS_MEASUREMENT,
  176. "device_class": SensorDeviceClass.POWER,
  177. },
  178. {
  179. "dps": FREQUENCY_DP,
  180. "name": "sensor_frequency",
  181. "unit": UnitOfFrequency.HERTZ,
  182. "state_class": STATE_CLASS_MEASUREMENT,
  183. "device_class": SensorDeviceClass.FREQUENCY,
  184. },
  185. {
  186. "dps": TEMPERATURE_DP,
  187. "name": "sensor_temperature",
  188. "unit": UnitOfTemperature.CELSIUS,
  189. "device_class": SensorDeviceClass.TEMPERATURE,
  190. "state_class": STATE_CLASS_MEASUREMENT,
  191. "testdata": (234, 23.4),
  192. },
  193. ]
  194. )
  195. self.mark_secondary(
  196. [
  197. "sensor_voltage_a",
  198. "sensor_current_a",
  199. "sensor_power_a",
  200. "sensor_power_factor_a",
  201. "sensor_energy_a",
  202. "sensor_voltage_b",
  203. "sensor_current_b",
  204. "sensor_power_b",
  205. "sensor_power_factor_b",
  206. "sensor_energy_b",
  207. "sensor_voltage_c",
  208. "sensor_current_c",
  209. "sensor_power_c",
  210. "sensor_power_factor_c",
  211. "sensor_energy_c",
  212. "sensor_total_current",
  213. "sensor_total_active_power",
  214. "sensor_frequency",
  215. "sensor_temperature",
  216. ]
  217. )