thomasloven / hass-plejd

🔹 Plejd BLE integration for Home Assistant
81 stars 10 forks source link

WRT-01 shows up with duplicate light entity #47

Closed oyvindwe closed 7 months ago

oyvindwe commented 7 months ago

I get a duplicate light entity for each of my WRT-01 devices.

I have 2 WRT-01 controlling the same DIM-01 device, and for this device I get 3 light entities. I can control the light from all 3 entities, but the entity from one of the switches resets to off if used to turn on.

I think the fix is to not create light entities form WRT-01 devices. I'm happy to try to fix this issue.

thomasloven commented 7 months ago

Note to self: The issue is that WRT-01 registers as a LIGHT in pyplejd, but it should be a SENSOR like WPH-01.

oyvindwe commented 7 months ago

I tried this locally, but then all the WRT-01 devices shows up twice, once without any entities, and once with a button entity.

I made sure to delete all existing devices and entities from previous and restart HA when testing.

From core.device_registry:

      {
        "area_id": "hobbyrommet",
        "config_entries": [
          "9852f24bcabf995207cd3209a49c449e"
        ],
        "configuration_url": null,
        "connections": [],
        "disabled_by": null,
        "entry_type": "service",
        "hw_version": null,
        "id": "99e2ae16a61b7e71497d0ed86e256678",
        "identifiers": [
          [
            "plejd",
            "D27968C507E9",
            "29"
          ]
        ],
        "manufacturer": "Plejd",
        "model": "WRT-01",
        "name_by_user": null,
        "name": "Taklampe ",
        "serial_number": null,
        "sw_version": "0.3.5",
        "via_device_id": null
      },
…
      {
        "area_id": "hobbyrommet",
        "config_entries": [
          "9852f24bcabf995207cd3209a49c449e"
        ],
        "configuration_url": null,
        "connections": [],
        "disabled_by": null,
        "entry_type": null,
        "hw_version": null,
        "id": "e5f6d4ece72fc8607a403ba1e9c77504",
        "identifiers": [
          [
            "plejd",
            "D27968C507E9"
          ]
        ],
        "manufacturer": "Plejd",
        "model": "WRT-01",
        "name_by_user": null,
        "name": "Taklampe ",
        "serial_number": null,
        "sw_version": "0.3.5",
        "via_device_id": null
      },

The entity is registered on the latter device (from core.entity_registry):

        "config_entry_id": "9852f24bcabf995207cd3209a49c449e",
        "device_class": null,
        "device_id": "e5f6d4ece72fc8607a403ba1e9c77504",
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "event.taklampe_0_pressed",
        "hidden_by": null,
        "icon": null,
        "id": "0b2c713751d3581470dd7cd094a52bdc",
        "has_entity_name": true,
        "name": null,
        "options": {
          "conversation": {
            "should_expose": false
          }
        },
        "original_device_class": "button",
        "original_icon": null,
        "original_name": "0 pressed",
        "platform": "plejd",
        "supported_features": 0,
        "translation_key": null,
        "unique_id": "D27968C507E9:29:0:press",
        "previous_unique_id": null,
        "unit_of_measurement": null
      },
oyvindwe commented 7 months ago

I see there is a slight difference in how sensor devices are registered in __init__.py and event.py. Aligning these fixes the duplicates.

thomasloven commented 7 months ago

Yes. https://github.com/thomasloven/hass_plejd/blob/master/custom_components/plejd/event.py#L86 should be "identifiers": {(DOMAIN, f"{self.device.BLEaddress}"), f"{self.device.address}"},