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