test_device.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from unittest import IsolatedAsyncioTestCase
  2. from unittest.mock import patch
  3. from custom_components.goldair_climate.const import (
  4. CONF_TYPE_DEHUMIDIFIER,
  5. CONF_TYPE_FAN,
  6. CONF_TYPE_GECO_HEATER,
  7. CONF_TYPE_GPCV_HEATER,
  8. CONF_TYPE_GPPH_HEATER,
  9. )
  10. from custom_components.goldair_climate.device import GoldairTuyaDevice
  11. from .const import (
  12. DEHUMIDIFIER_PAYLOAD,
  13. FAN_PAYLOAD,
  14. GECO_HEATER_PAYLOAD,
  15. GPCV_HEATER_PAYLOAD,
  16. GPPH_HEATER_PAYLOAD,
  17. )
  18. class TestDevice(IsolatedAsyncioTestCase):
  19. def setUp(self):
  20. patcher = patch("pytuya.Device")
  21. self.addCleanup(patcher.stop)
  22. self.mock_api = patcher.start()
  23. self.subject = GoldairTuyaDevice(
  24. "Some name", "some_dev_id", "some.ip.address", "some_local_key", None
  25. )
  26. def test_configures_pytuya_correctly(self):
  27. self.mock_api.assert_called_once_with(
  28. "some_dev_id", "some.ip.address", "some_local_key", "device"
  29. )
  30. self.assertIs(self.subject._api, self.mock_api())
  31. def test_name(self):
  32. """Returns the name given at instantiation."""
  33. self.assertEqual("Some name", self.subject.name)
  34. def test_unique_id(self):
  35. """Returns the unique ID presented by the API class."""
  36. self.assertIs(self.subject.unique_id, self.mock_api().id)
  37. def test_device_info(self):
  38. """Returns generic info plus the unique ID for categorisation."""
  39. self.assertEqual(
  40. self.subject.device_info,
  41. {
  42. "identifiers": {("goldair_climate", self.mock_api().id)},
  43. "name": "Some name",
  44. "manufacturer": "Goldair",
  45. },
  46. )
  47. async def test_detects_geco_heater_payload(self):
  48. self.subject._cached_state = GECO_HEATER_PAYLOAD
  49. self.assertEqual(
  50. await self.subject.async_inferred_type(), CONF_TYPE_GECO_HEATER
  51. )
  52. async def test_detects_gpcv_heater_payload(self):
  53. self.subject._cached_state = GPCV_HEATER_PAYLOAD
  54. self.assertEqual(
  55. await self.subject.async_inferred_type(), CONF_TYPE_GPCV_HEATER
  56. )
  57. async def test_detects_gpph_heater_payload(self):
  58. self.subject._cached_state = GPPH_HEATER_PAYLOAD
  59. self.assertEqual(
  60. await self.subject.async_inferred_type(), CONF_TYPE_GPPH_HEATER
  61. )
  62. async def test_detects_dehumidifier_payload(self):
  63. self.subject._cached_state = DEHUMIDIFIER_PAYLOAD
  64. self.assertEqual(
  65. await self.subject.async_inferred_type(), CONF_TYPE_DEHUMIDIFIER
  66. )
  67. async def test_detects_fan_payload(self):
  68. self.subject._cached_state = FAN_PAYLOAD
  69. self.assertEqual(await self.subject.async_inferred_type(), CONF_TYPE_FAN)