-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Add sensors for switchbot cloud integration #147663
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
base: dev
Are you sure you want to change the base?
Conversation
Hey there @SeraphicRav, @laurence-presland, @Gigatrappeur, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
LIGHTLEVEL_DESCRIPTION = SensorEntityDescription( | ||
key="lightLevel", | ||
translation_key="light_level", | ||
native_unit_of_measurement="Level", |
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 use a translatable unit of measurement
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.
lightLevel returns an int type. The device will collect light intensity and then return different light levels.
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. It would be better if it returned the lux value directly.
But if not, it's possible to adapt the icon to the level in an icons.json
file. Here's an example:
{
"entity": {
"sensor": {
"light_level": {
"default": "mdi:brightness-7",
"state": {
"1": "mdi:brightness-1",
"2": "mdi:brightness-1",
"3": "mdi:brightness-2",
"4": "mdi:brightness-3",
"5": "mdi:brightness-4",
"6": "mdi:brightness-5",
"7": "mdi:brightness-5",
"8": "mdi:brightness-6",
"9": "mdi:brightness-6",
"10": "mdi:brightness-7"
}
}
}
}
}
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.
done
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.
Is it ok with light_level?
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.
There is still the problem with
native_unit_of_measurement="Level",
That does not make sense.
icon="mdi:door", | ||
translation_key="contact_open", | ||
device_class=SensorDeviceClass.ENUM, | ||
options=["open", "closed", "timeout"], |
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.
What is timeout for?
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.
api return 3 kinds of status as below
the open state of the sensor. open, close, or timeOutNotClose
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.
When does that last thing happen?
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 means that the sensor detected that the door opening time was too long and failed to detect the door closing within the threshold time range set by the firmware.
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.
Hmm, do we get updates for this via the webhook?
I kinda think that exposing a door state as a binary sensor makes more sense as we can use the device class to tell home assistant its genuinely a door (which is nicer with automating).
But then I'm looking for the best way to show this extra state, maybe an event entity
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.
Oh if that's the case we can set the door to open indeed.
Would that other state happen often and what should the user do to fix it?
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 status is to remind the user that the door has not been closed. The user can actively set the time interval, that is, after opening the door, the door has not been closed after the set time
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.
Maybe it can be a separate binary sensor
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.
sure
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.
I have set this as the binary sensor now
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
e9dd9d1
to
ba69e0e
Compare
@@ -429,7 +429,7 @@ | |||
'state': '55', | |||
}) | |||
# --- | |||
# name: test_meter[device_info3-3][sensor.hub_3_name_light_level-entry] | |||
# name: test_meter[device_info3-3][sensor.hub_3_name_none-entry] |
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.
You should:
- generate translations
- update snapshots
It is required when the entity name has changed
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.
ok
d6608d6
to
96b0e82
Compare
if self.entity_description.keys: | ||
return any( | ||
self.coordinator.data.get(key) for key in self.entity_description.keys | ||
) | ||
|
||
if self.entity_description.key == "openState": | ||
value = self.coordinator.data.get(self.entity_description.key) | ||
return value in {"open", "timeOutNotClose"} | ||
|
||
if ( | ||
self.entity_description.key == "moveDetected" | ||
and self.device.device_type == "Motion Sensor" | ||
): | ||
return ( | ||
self.coordinator.data.get(self.entity_description.key) is True | ||
or self.coordinator.data.get("detectionState", "") == "DETECTED" | ||
) |
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.
Instead of blending the entity logic with the generic entity, I would recommend to change the entity description and make it get a function that can transform the coordinator.data into a bool. This way you can move all the entity specifics to the entity
value = self.coordinator.data.get(self.entity_description.key) | ||
|
||
if self.entity_description.key == "lightLevel": | ||
self._attr_native_value = str(value) if value is not None else None |
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.
why the str
?
Breaking change
Proposed change
Add sensors for switchbot integration
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: