Skip to content

Add unique_id to homematic_cloud#16828

Merged
MartinHjelmare merged 2 commits intohome-assistant:devfrom
sander76:dev
Sep 25, 2018
Merged

Add unique_id to homematic_cloud#16828
MartinHjelmare merged 2 commits intohome-assistant:devfrom
sander76:dev

Conversation

@sander76
Copy link
Copy Markdown
Contributor

@sander76 sander76 commented Sep 24, 2018

Description:

Add unique_id property to homematic_cloud entities to prevent mixup of devices when hass is restarted.

Related issue (if applicable): fixes #
#16794

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

@sander76
Copy link
Copy Markdown
Contributor Author

sander76 commented Sep 24, 2018

@mxworm I created a PR for the issue.

I consulted balloob for the solution. He requested adding device_info to hmip. So if you've got some spare time ... ;-)
https://developers.home-assistant.io/docs/en/device_registry_index.html

@MartinHjelmare MartinHjelmare changed the title add unique_id to homematic_cloud Add unique_id to homematic_cloud Sep 25, 2018
@MartinHjelmare MartinHjelmare merged commit 069b819 into home-assistant:dev Sep 25, 2018
@ghost ghost removed the in progress label Sep 25, 2018
@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 27, 2018

@sander76 Sorry, I'm a bit late, but maybe to use the device.modelType instead of the classname would be the better choice as this is also used in the homematicIP app.

@sander76
Copy link
Copy Markdown
Contributor Author

@mxworm Thought about that too, but using device.modelType is not unique to hass entities. For example the current sensing and switching capabilities of the pluggable switch (one single modelType) will be split into two separate entities.

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 30, 2018

@sander76 I would like to have it implemented as the name property:

@property
def unique_id(self):
  """Device unique ID"""
  id = "{}_{}".format(self._device.modelType, self._device.id)
  if self.post is not None and self.post != '':
    id = "{}_{}_{}".format(self._device.modelType,
                                   self.post, self._device.id).lower()
  return id

@sander76
Copy link
Copy Markdown
Contributor Author

@mxworm what does 'self.post' stand for ?

@sander76
Copy link
Copy Markdown
Contributor Author

@mxworm does your code result in a unique entity_id ?

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 30, 2018

@sander76 The self.post if added to the name as a post-fix... it contains mainly the sensor type and yes its's unique.

Wohnzimmer Temperature, hmip-wth_temperature_3014f711a000xxxxxxxxxxxxx (HMIP-WTH)
Wohnzimmer Humidity, hmip-wth_humidity_3014f711a00xxxxxxxxxxxx (HMIP-WTH)
Wohnzimmer Heating, hmip-etrv_heating_3014f711a00xxxxxxxxxxxxx (HMIP-eTRV)

I have just missed a .lower() in the first id = .... line
id = "{}_{}".format(self._device.modelType, self._device.id).lower()

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 30, 2018

@sander76 But for the "braking change" I any how miss at the moment the hass in the init function :-|
self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, self.unique_id, hass=self.hass)

@sander76
Copy link
Copy Markdown
Contributor Author

@mxworm it is not necessary to call that function (anymore). That is all taken care of by the entity manager in Hass. We just need a unique ID property.

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 30, 2018

@sander76 Thanks, this I missed :-)

@sander76
Copy link
Copy Markdown
Contributor Author

@mxworm I missed the self.post property. Interesting.. looks nice

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Sep 30, 2018

@sander76 I know its not the best way, but I would prefer it instead of the classname.

@worm-ee
Copy link
Copy Markdown
Contributor

worm-ee commented Oct 1, 2018

@sander76 What do you think?
worm-ee@cc53095

@balloob balloob mentioned this pull request Oct 12, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants