doudz / homeassistant-zigate

zigate component for Home Assistant
MIT License
48 stars 13 forks source link

Can't Remove Entity on Hass #127

Closed nguyenanhgiau closed 4 years ago

nguyenanhgiau commented 4 years ago

Hi Doudz, I find that you add entity with command (for ZiGateSwitch)

key = '{}-{}-{}'.format(ieee,
                                            'switch',
                                            endpoint
                                            )
                    if key in hass.data[DATA_ZIGATE_ATTRS]:
                        continue
                    _LOGGER.debug(('Creating switch '
                                   'for device '
                                   '{} {}').format(device,
                                                   endpoint))
                    entity = ZiGateSwitch(hass, device, endpoint)
                    devs.append(entity)
                    hass.data[DATA_ZIGATE_ATTRS][key] = entity

But, in function device_removed, you do this:

entity = hass.data[DATA_ZIGATE_DEVICES][ieee]
        component.async_remove_entity(entity.entity_id)
        del hass.data[DATA_ZIGATE_DEVICES][ieee]

You should use key instead of ieee. And you should use command: hass.add_job(component.async_remove_entity(entity.entity_id)) instead of component.async_remove_entity(entity.entity_id)