-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide entity_id to avoid sensor mixup (fixes #7636). Use async_dispatcher. Provide icon. #7946
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good fix. You can also not use DOMAIN
from component in a sensor namespace. Please change this and don't use the same name twice:
https://github.com/molobrakos/home-assistant/blob/3081853ee45aabf0ec3d9a160b54a46e6211198b/homeassistant/components/volvooncall.py#L35-L36
Other points that you should a bit cleanup on your code in a later PR 😅 :
- https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/volvooncall.py#L71-L76 your are the first Person they do that in hass. Can you export this data class on root of your component, please.
- https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/volvooncall.py#L169 we use format string normaly
- https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/device_tracker/volvooncall.py#L33 It is not good designe to forward the callback into
hass.data
. Please use dispatcher fromhelper/dispatcher
. - Don't use
DOMAIN
forhass.data
, it overwrite the localDOMAIN
constante and can make problem in future changes of core. Some people use aDATA_*
constante for that
|
3081853
to
1c0a608
Compare
a96f293
to
1c0a608
Compare
1c0a608
to
f48ff4d
Compare
f48ff4d
to
73250ec
Compare
@@ -92,7 +96,7 @@ def update_vehicle(vehicle): | |||
if isinstance(entity, Entity): | |||
entity.schedule_update_ha_state() | |||
else: | |||
entity(vehicle) # device tracker | |||
async_dispatcher_send(SIGNAL_VEHICLE_SEEN, vehicle) # device tracker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (85 > 79 characters)
73250ec
to
536f273
Compare
536f273
to
de9b546
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not the idea to do the cleanup with this PR, but good work. Only the point of DOMAIN is a bit missunderstand. I hope with my last Change request you understand it now. You can use DOMAIN inside your component for hass.data but you should not Import DOMAIN as DOMAIN in a platform they have a other domain like device_tracker or sensor.
@@ -123,6 +126,13 @@ def __init__(self, hass, vin, attribute): | |||
self._state.entities[self._vin].append(self) | |||
|
|||
@property | |||
def entity_id(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this into sensor/volvooncall entity and import the domain from sensor. Now you see why you should not import the DOMAIN as DOMAIN inside a platform from a other component then volvooncall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for feedback - do I understand correctly that everything is fine if it is kept as it is, i.e. entity_id
is specified in class VolvoEntity
, which is defined in components/volvooncall
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do you still prefer that I just rename the sensors instead of providing unique entity_id
:s? (I still prefer the latter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. You can move the property into entity class inside sensor/volvooncall.py
and use the DOMAIN from sensor/__init__.py
or you remove the entity_id
property and use a unique Name that generate a unique entity_id inside core. All other is perfect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help me understand why you think it is wrong to keep it in the VolvoEntity base class (base class for both the implementation within sensor/ and binary_sensor/)?
de9b546
to
74ebd95
Compare
74ebd95
to
c21f85e
Compare
c21f85e
to
c1f6a89
Compare
'fuel_amount': ('sensor', 'Fuel', 'mdi:gas-station', 'L'), | ||
'fuel_amount_level': ('sensor', 'Fuel', 'mdi:water-percent', '%'), | ||
'fuel_amount': ('sensor', 'Fuel amount', 'mdi:gas-station', 'L'), | ||
'fuel_amount_level': ('sensor', 'Fuel level', 'mdi:water-percent', '%'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (85 > 79 characters)
from homeassistant.util.dt import utcnow | ||
from homeassistant.util import slugify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'homeassistant.util.slugify' imported but unused
c1f6a89
to
b0396a4
Compare
b0396a4
to
b4ee484
Compare
b4ee484
to
6684af0
Compare
6684af0
to
6f0279f
Compare
…s some smaller fixes.
6f0279f
to
c6492d3
Compare
Description:
Related issue (if applicable): fixes #
#7636
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass