sanjoyg / dirigera_platform

HomeAssistant Integration for Dirigera Platform
MIT License
72 stars 8 forks source link

JSON Dump of Starkvind air purifier #6

Closed acces90 closed 4 months ago

acces90 commented 4 months ago

Here's a dump of one of my Starkvind air purifiers that you asked for @sanjoyg:

{
      "id":"7cef9a41-6253-4608-a99a-6968fa8956a7_1",
      "type":"airPurifier",
      "deviceType":"airPurifier",
      "createdAt":"2023-10-03T15:47:01.000Z",
      "isReachable":true,
      "lastSeen":"2024-02-27T17:49:02.000Z",
      "attributes":{
         "customName":"Luftreiniger Schlafzimmer",
         "model":"STARKVIND Air purifier table",
         "manufacturer":"IKEA of Sweden",
         "firmwareVersion":"1.1.001",
         "hardwareVersion":"1",
         "serialNumber":"CC86ECFFFE83299A",
         "productCode":"E2006",
         "fanMode":"auto",
         "fanModeSequence":"lowMediumHighAuto",
         "motorState":10,
         "motorRuntime":746614,
         "filterElapsedTime":191955,
         "filterAlarmStatus":false,
         "filterLifetime":259200,
         "childLock":false,
         "statusLight":true,
         "currentPM25":25,
         "identifyStarted":"2000-01-01T00:00:00.000Z",
         "identifyPeriod":0,
         "permittingJoin":false,
         "otaStatus":"upToDate",
         "otaState":"readyToCheck",
         "otaProgress":0,
         "otaPolicy":"autoUpdate",
         "otaScheduleStart":"00:00",
         "otaScheduleEnd":"00:00"
      },
      "capabilities":{
         "canSend":[

         ],
         "canReceive":[
            "customName",
            "fanMode",
            "fanModeSequence",
            "motorState",
            "childLock",
            "statusLight"
         ]
      },
      "room":{
         "id":"37b3a4a8-c360-4055-9e56-9185d4a09491",
         "name":"Schlafzimmer\\xa0",
         "color":"ikea_pink_no_8",
         "icon":"rooms_bed"
      },
      "deviceSet":[

      ],
      "remoteLinks":[

      ],
      "isHidden":false
   }

I described the values that the canReceive attributes can handle in the air_purifier.py that I wrote for leggin/dirigera repository (https://github.com/Leggin/dirigera/blob/main/src/dirigera/devices/air_purifier.py)

EDIT: The *time attributes are minutes, btw. I forgot to comment that in the device code. Also the "fanModeSequence":"lowMediumHighAuto" thing.. it's receivable but I didn't find any values you can use with it, tbh. i believe it can be ignored in the integration since not even the IKEA Home Smart App is giving any options to set it to

sanjoyg commented 4 months ago

I got it almost done, but would need some testing. Is the motorRunTime also a time attribute that is in "minutes" or is it something different?

sanjoyg commented 4 months ago

Added support, do test it and let me know. This is available in the latest release

acces90 commented 4 months ago

The motorRunTime is also in minutes. Its the total time the fan has worked basically. In the case of this Starkvind it would be around 518 days it's been running.

I will test the new version and report! thank you

acces90 commented 4 months ago

it finds the air purifiers but the entities are not available. I believe you forgot the ".attributes", as in fan.py line 125 it should be return self._json_data.attributes.motor_state

Logger: homeassistant.components.fan
Source: helpers/entity_platform.py:352
Integration: Lüfter ([documentation](https://www.home-assistant.io/integrations/fan), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+fan%22))
First occurred: 18:18:34 (1 occurrences)
Last logged: 18:18:34

Error while setting up dirigera_platform platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 352, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1600, in state
    if (is_on := self.is_on) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/fan.py", line 272, in is_on
    return self._device.is_on
           ^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/fan.py", line 178, in is_on
    if self.available and self.motor_state > 0:
                          ^^^^^^^^^^^^^^^^
  File "/config/custom_components/dirigera_platform/fan.py", line 125, in motor_state
    return self._json_data.motor_state
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'AirPurifier' object has no attribute 'motor_state'. Did you mean: 'set_motor_state'?
acces90 commented 4 months ago

I made a fork and fixed some stuff in fan.py (attributes, and icons). Everything seems to work just fine now! thank you for your work <3

Bildschirmfoto 2024-02-28 um 22 35 37

we can either merge or you just copy paste the few edits from my fork.

the only thing I don't get is why every entity act's like a switch when clicked?

Bildschirmfoto 2024-02-28 um 22 12 52
sanjoyg commented 4 months ago

Thank you, you should have just submitted a pull request. I copied your code and pushed a new release.

Not sure why when its clicked shows a switch.

BeauGiles commented 3 months ago

Hi, I can't manage to get the JSON dump (nothing appears in the logs after calling the service???) but my air purifier isn't showing in HA.

From the error log

Error while setting up dirigera_platform platform for fan Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 350, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/dirigera_platform/fan.py", line 48, in async_setup_entry hub_air_purifiers = await hass.async_add_executor_job(hub.get_air_purifiers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/dirigera/hub/hub.py", line 129, in get_air_purifiers return [dict_to_air_purifier(air_p, self) for air_p in airpurifiers] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/dirigera/devices/air_purifier.py", line 77, in dict_to_air_purifier return AirPurifier( ^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 341, in __init__ raise validation_error pydantic.error_wrappers.ValidationError: 1 validation error for AirPurifier attributes -> fanMode value is not a valid enumeration member; permitted: 'low', 'medium', 'high', 'auto' (type=type_error.enum; enum_values=[<FanModeEnum.LOW: 'low'>, <FanModeEnum.MEDIUM: 'medium'>, <FanModeEnum.HIGH: 'high'>, <FanModeEnum.AUTO: 'auto'>])

-

Error adding entity None for domain sensor with platform dirigera_platform Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities await coro File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 725, in _async_add_entity device = dev_reg.async_get(self.hass).async_get_or_create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: homeassistant.helpers.device_registry.DeviceRegistry.async_get_or_create() argument after ** must be a mapping, not SensorDeviceClass

Check out this STARKVIND from IKEA. Here’s a little more information: https://ingka.page.link/Mn5pCyvc17aTX8ML8

sanjoyg commented 3 months ago

Please enable debug for the integration

On Sun, 24 Mar 2024 at 17:58, Beau @.***> wrote:

Hi, I can't manage to get the JSON dump (nothing appears in the logs after calling the service???) but my air purifier isn't showing in HA.

From the error log

Error while setting up dirigera_platform platform for fan Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 350, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/dirigera_platform/fan.py", line 48, in async_setup_entry hub_air_purifiers = await hass.async_add_executor_job(hub.get_air_purifiers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/dirigera/hub/hub.py", line 129, in get_air_purifiers return [dict_to_air_purifier(air_p, self) for air_p in airpurifiers] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/dirigera/devices/air_purifier.py", line 77, in dict_to_air_purifier return AirPurifier( ^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 341, in init raise validation_error pydantic.error_wrappers.ValidationError: 1 validation error for AirPurifier attributes -> fanMode value is not a valid enumeration member; permitted: 'low', 'medium', 'high', 'auto' (type=type_error.enum; enum_values=[<FanModeEnum.LOW: 'low'>, <FanModeEnum.MEDIUM: 'medium'>, <FanModeEnum.HIGH: 'high'>, <FanModeEnum.AUTO: 'auto'>])

-

Error adding entity None for domain sensor with platform dirigera_platform Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities await coro File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 725, in _async_add_entity device = dev_reg.async_get(self.hass).async_get_or_create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: homeassistant.helpers.device_registry.DeviceRegistry.async_get_or_create() argument after ** must be a mapping, not SensorDeviceClass

Check out this STARKVIND from IKEA. Here’s a little more information: https://ingka.page.link/Mn5pCyvc17aTX8ML8

— Reply to this email directly, view it on GitHub https://github.com/sanjoyg/dirigera_platform/issues/6#issuecomment-2016793784, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2X3CRLCQ2C3OWZDB43PA3YZ3BIDAVCNFSM6AAAAABD4Q2OX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJWG44TGNZYGQ . You are receiving this because you modified the open/close state.Message ID: @.***>