test_pc321ty_energy_meter.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. """Tests for the PC321-TY Power Clamp Energy meter"""
  2. from homeassistant.components.sensor import (
  3. SensorDeviceClass,
  4. STATE_CLASS_MEASUREMENT,
  5. STATE_CLASS_TOTAL_INCREASING,
  6. )
  7. from homeassistant.const import (
  8. ELECTRIC_CURRENT_AMPERE,
  9. ELECTRIC_POTENTIAL_VOLT,
  10. FREQUENCY_HERTZ,
  11. UnitOfEnergy,
  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",
  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": ELECTRIC_POTENTIAL_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": ELECTRIC_CURRENT_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. "device_class": SensorDeviceClass.ENERGY,
  90. "state_class": STATE_CLASS_TOTAL_INCREASING,
  91. "testdata": (12345, 123.45),
  92. },
  93. {
  94. "dps": VOLTAGE2_DP,
  95. "name": "sensor_voltage_b",
  96. "unit": ELECTRIC_POTENTIAL_VOLT,
  97. "device_class": SensorDeviceClass.VOLTAGE,
  98. "state_class": STATE_CLASS_MEASUREMENT,
  99. "testdata": (2348, 234.8),
  100. },
  101. {
  102. "dps": CURRENT2_DP,
  103. "name": "sensor_current_b",
  104. "unit": ELECTRIC_CURRENT_AMPERE,
  105. "device_class": SensorDeviceClass.CURRENT,
  106. "state_class": STATE_CLASS_MEASUREMENT,
  107. "testdata": (4567, 4.567),
  108. },
  109. {
  110. "dps": POWER2_DP,
  111. "name": "sensor_power_b",
  112. "unit": UnitOfPower.WATT,
  113. "device_class": SensorDeviceClass.POWER,
  114. "state_class": STATE_CLASS_MEASUREMENT,
  115. },
  116. {
  117. "dps": PFACTOR2_DP,
  118. "name": "sensor_power_factor_b",
  119. "device_class": SensorDeviceClass.POWER_FACTOR,
  120. "state_class": STATE_CLASS_MEASUREMENT,
  121. "testdata": (5000, 50.00),
  122. },
  123. {
  124. "dps": ENERGY2_DP,
  125. "name": "sensor_energy_b",
  126. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  127. "device_class": SensorDeviceClass.ENERGY,
  128. "state_class": STATE_CLASS_TOTAL_INCREASING,
  129. "testdata": (12345, 123.45),
  130. },
  131. {
  132. "dps": VOLTAGE3_DP,
  133. "name": "sensor_voltage_c",
  134. "unit": ELECTRIC_POTENTIAL_VOLT,
  135. "device_class": SensorDeviceClass.VOLTAGE,
  136. "state_class": STATE_CLASS_MEASUREMENT,
  137. "testdata": (2348, 234.8),
  138. },
  139. {
  140. "dps": CURRENT3_DP,
  141. "name": "sensor_current_c",
  142. "unit": ELECTRIC_CURRENT_AMPERE,
  143. "device_class": SensorDeviceClass.CURRENT,
  144. "state_class": STATE_CLASS_MEASUREMENT,
  145. "testdata": (4567, 4.567),
  146. },
  147. {
  148. "dps": POWER3_DP,
  149. "name": "sensor_power_c",
  150. "unit": UnitOfPower.WATT,
  151. "state_class": STATE_CLASS_MEASUREMENT,
  152. "device_class": SensorDeviceClass.POWER,
  153. },
  154. {
  155. "dps": PFACTOR3_DP,
  156. "name": "sensor_power_factor_c",
  157. "device_class": SensorDeviceClass.POWER_FACTOR,
  158. "state_class": STATE_CLASS_MEASUREMENT,
  159. "testdata": (5000, 50.00),
  160. },
  161. {
  162. "dps": ENERGY3_DP,
  163. "name": "sensor_energy_c",
  164. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  165. "device_class": SensorDeviceClass.ENERGY,
  166. "state_class": STATE_CLASS_TOTAL_INCREASING,
  167. "testdata": (12345, 123.45),
  168. },
  169. {
  170. "dps": TOTALCURRENT_DP,
  171. "name": "sensor_total_current",
  172. "unit": ELECTRIC_CURRENT_AMPERE,
  173. "device_class": SensorDeviceClass.CURRENT,
  174. "state_class": STATE_CLASS_MEASUREMENT,
  175. "testdata": (12345, 12.345),
  176. },
  177. {
  178. "dps": TOTALPOWER_DP,
  179. "name": "sensor_total_active_power",
  180. "unit": UnitOfPower.WATT,
  181. "state_class": STATE_CLASS_MEASUREMENT,
  182. "device_class": SensorDeviceClass.POWER,
  183. },
  184. {
  185. "dps": FREQUENCY_DP,
  186. "name": "sensor_frequency",
  187. "unit": FREQUENCY_HERTZ,
  188. "state_class": STATE_CLASS_MEASUREMENT,
  189. "device_class": SensorDeviceClass.FREQUENCY,
  190. },
  191. {
  192. "dps": TEMPERATURE_DP,
  193. "name": "sensor_temperature",
  194. "unit": UnitOfTemperature.CELSIUS,
  195. "device_class": SensorDeviceClass.TEMPERATURE,
  196. "state_class": STATE_CLASS_MEASUREMENT,
  197. "testdata": (234, 23.4),
  198. },
  199. ]
  200. )
  201. self.mark_secondary(
  202. [
  203. "sensor_voltage_a",
  204. "sensor_current_a",
  205. "sensor_power_a",
  206. "sensor_power_factor_a",
  207. "sensor_energy_a",
  208. "sensor_voltage_b",
  209. "sensor_current_b",
  210. "sensor_power_b",
  211. "sensor_power_factor_b",
  212. "sensor_energy_b",
  213. "sensor_voltage_c",
  214. "sensor_current_c",
  215. "sensor_power_c",
  216. "sensor_power_factor_c",
  217. "sensor_energy_c",
  218. "sensor_total_current",
  219. "sensor_total_active_power",
  220. "sensor_frequency",
  221. "sensor_temperature",
  222. ]
  223. )