Add nearest method to get data for Airly integration (#44288)
* Add nearest method * Add tests * Move urls to consts * Simplify config flow * Fix tests * Update tests * Use in instead get * Fix AirlyError message in tests * Fix manual update entity tests * Clean up tests * Fix after rebase * Increase test coverage * Format the code * Fix after rebase
This commit is contained in:
parent
76537305e2
commit
2e50c1be8e
8 changed files with 102 additions and 27 deletions
|
@ -87,13 +87,13 @@ class AirlyAirQuality(CoordinatorEntity, AirQualityEntity):
|
|||
@round_state
|
||||
def particulate_matter_2_5(self):
|
||||
"""Return the particulate matter 2.5 level."""
|
||||
return self.coordinator.data[ATTR_API_PM25]
|
||||
return self.coordinator.data.get(ATTR_API_PM25)
|
||||
|
||||
@property
|
||||
@round_state
|
||||
def particulate_matter_10(self):
|
||||
"""Return the particulate matter 10 level."""
|
||||
return self.coordinator.data[ATTR_API_PM10]
|
||||
return self.coordinator.data.get(ATTR_API_PM10)
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
|
@ -120,12 +120,19 @@ class AirlyAirQuality(CoordinatorEntity, AirQualityEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
attrs = {
|
||||
LABEL_AQI_DESCRIPTION: self.coordinator.data[ATTR_API_CAQI_DESCRIPTION],
|
||||
LABEL_ADVICE: self.coordinator.data[ATTR_API_ADVICE],
|
||||
LABEL_AQI_LEVEL: self.coordinator.data[ATTR_API_CAQI_LEVEL],
|
||||
LABEL_PM_2_5_LIMIT: self.coordinator.data[ATTR_API_PM25_LIMIT],
|
||||
LABEL_PM_2_5_PERCENT: round(self.coordinator.data[ATTR_API_PM25_PERCENT]),
|
||||
LABEL_PM_10_LIMIT: self.coordinator.data[ATTR_API_PM10_LIMIT],
|
||||
LABEL_PM_10_PERCENT: round(self.coordinator.data[ATTR_API_PM10_PERCENT]),
|
||||
}
|
||||
if ATTR_API_PM25 in self.coordinator.data:
|
||||
attrs[LABEL_PM_2_5_LIMIT] = self.coordinator.data[ATTR_API_PM25_LIMIT]
|
||||
attrs[LABEL_PM_2_5_PERCENT] = round(
|
||||
self.coordinator.data[ATTR_API_PM25_PERCENT]
|
||||
)
|
||||
if ATTR_API_PM10 in self.coordinator.data:
|
||||
attrs[LABEL_PM_10_LIMIT] = self.coordinator.data[ATTR_API_PM10_LIMIT]
|
||||
attrs[LABEL_PM_10_PERCENT] = round(
|
||||
self.coordinator.data[ATTR_API_PM10_PERCENT]
|
||||
)
|
||||
return attrs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue