Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions homeassistant/components/cover/tahoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ class TahomaCover(TahomaDevice, CoverDevice):
def __init__(self, tahoma_device, controller):
"""Initialize the Tahoma device."""
super().__init__(tahoma_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.unique_id)
eid = ENTITY_ID_FORMAT.format(self.unique_id)
# strip off the RTS or the IO ID from the entity ID
if eid.rfind('_rts') > 0:
eid = eid[:eid.rfind('_rts')]
elif eid.rfind('_io') > 0:
eid = eid[:eid.rfind('_io')]
self.entity_id = eid

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you realy need to set the entity_id and don't let's auto generate from internal core/name ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is that - as mentioned above - the current entity_id looks like <custom_name>_rts_<NNN>, where <NNN> is a very long numeric ID internally used by the TaHoma box to reference the shutters. This makes writing automations pretty unpractical (and the produced code unreadable).

IMHO Home Assistant should abstract from such platform-dependent details and expose high-level identifiers, so I believe it is definitely worth to override the auto-generated identifiers here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvizeli Currently an entity id look like this: cover.bedroom_middle_io12345678901234567890 . Having cover.bedroom_middle would be more desireable, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Home-Assistant generate automatic entity_id with name. Remove the entity_id and the core do that automatic. For unique_id, you can only use the NN if they is unique.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the question is about the pre-existing statement at L36, right? Do I understand correctly that leaving entity_id unassigned will make Home Assistant auto-generate an appropriate name?
There's no question about unique_id including the full identifier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answering to my own question: yes. Even better, the patch will be to remove L36 altogether.


def update(self):
"""Update method."""
Expand All @@ -46,12 +52,16 @@ def current_cover_position(self):

0 is closed, 100 is fully open.
"""
position = 100 - self.tahoma_device.active_states['core:ClosureState']
if position <= 5:
return 0
if position >= 95:
return 100
return position
try:
position = 100 - \
self.tahoma_device.active_states['core:ClosureState']
if position <= 5:
return 0
if position >= 95:
return 100
return position
except KeyError:
return None

def set_cover_position(self, position, **kwargs):
"""Move the cover to a specific position."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tahoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ def apply_action(self, cmd_name, *args):
from tahoma_api import Action
action = Action(self.tahoma_device.url)
action.add_command(cmd_name, *args)
self.controller.apply_actions('', [action])
self.controller.apply_actions('HomeAssistant', [action])