-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Add sensor platform for Xiaomi Miio fans #54564
Add sensor platform for Xiaomi Miio fans #54564
Conversation
This pull request needs to be manually signed off by @home-assistant/core before it can get merged. |
Hey there @rytilahti, @syssi, @starkillerOG, mind taking a look at this pull request as it has been labeled with an integration ( |
@jbouwh Please have a look. |
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.
Look good overall a few suggestions.
MODELS_HUMIDIFIER_MIIO, | ||
MODELS_HUMIDIFIER_MIOT, | ||
MODELS_HUMIDIFIER_MJJSQ, | ||
MODELS_PURIFIER_MIIO, | ||
MODELS_PURIFIER_MIOT, | ||
) | ||
from .device import XiaomiCoordinatedMiioEntity, XiaomiMiioEntity | ||
from .gateway import XiaomiGatewayDevice |
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.
The constant in line 64->78 does no seem to be reference anymore.
UNIT_LUMEN = "lm"
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.
UNIT_LUMEN
is used in the line 180.
@@ -238,13 +362,34 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
elif model in MODELS_HUMIDIFIER_MIIO: | |||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE] |
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.
Assignment of device is all the same perhaps we can do the check for the condition in the else statement first.
Just get the value for KEY_DEVICE
if key if it is available (perhaps use get).
Background:
AIR_MONITOR_PLATFORMS
(MODELS_AIR_MONITOR
) (flow_type == CONF_DEVICE
) and GATEWAY_PLATFORMS
(flow_type == CONF_GATEWAY
) are initializing then sensor platform too.
sensors = PURIFIER_MIIO_SENSORS | ||
elif model in MODELS_PURIFIER_MIOT: | ||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE] | ||
sensors = PURIFIER_MIOT_SENSORS | ||
else: |
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.
In a next PR we should also move there sensors to a coordinated context
sensors = HUMIDIFIER_MIIO_SENSORS | ||
elif model == MODEL_AIRPURIFIER_V2: |
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.
Perhaps we could do the model to sensors translation using a constant dict
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.
Good idea.
), | ||
ATTR_AQI: XiaomiMiioSensorDescription( | ||
key=ATTR_AQI, | ||
name="Air Quality Index", |
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 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.
LGTM
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.
Looks good
state_class=STATE_CLASS_MEASUREMENT, | ||
attributes=( | ||
"filter_hours_used", | ||
"filter_rfid_product_id", |
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 sounds like it's static info. We only want to have dynamic info related to the entity state in the state attributes. There are only some exceptions like attribution or if the info is essential for automations.
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 filter_rfid_product_id
looks like this : 0:0:30:33. It could change if you use a different filter product. The filter_type
is extracted/is part of the product id
.
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.
Looks good!
We should mention that filter product id and rf id tag were removed in the breaking changes paragraph. |
Please have a look at the error at #54625. The |
I merged this pull to sync the code base. |
This issue is caused here: core/homeassistant/components/xiaomi_miio/sensor.py Lines 437 to 446 in 3d5d740
When state is None. No further checks should be performed. When the cover is removed the backend returns Suggestion is to insert one line of code... core/homeassistant/components/xiaomi_miio/sensor.py Lines 434 to 439 in 3d5d740
if self._state is None:
return None core/homeassistant/components/xiaomi_miio/sensor.py Lines 440 to 446 in 3d5d740
|
Done |
Great catch. Fixed. |
Why did we have the valid max and min value checks? Don't we need them anymore? |
With earlier versions of |
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.
Good!
@jbouwh please confirm we can merge here. |
I'll check within a few hours |
Tested. All seems ok. The water_level sensor turn to |
Thanks! |
Breaking change
The following fan entity attributes
temperature
,humidity
,aqi
,purify volume
,filter life remaining
,filter hours used
,co2
,illuminance
,motor speed
andmotor2 speed
has been migrated to the senor entity.Users need to update their automations.
The
filter_rfid_product_id
andfilter_rfid_tag
fan entity attributes has been removed as they are of little use to users.Proposed change
This PR migrates the existing fan attributes to the sensor entities.
Type of change
Additional information
Checklist
black --fast 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
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: