mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Fix unreachable Netatmo sensor returning false values (#105954)
* Fix unreachable sensor returning false values * Clean up unnecessary code
This commit is contained in:
parent
94d22c936e
commit
57a6effd70
@ -12,5 +12,5 @@
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pyatmo"],
|
||||
"requirements": ["pyatmo==7.6.0"]
|
||||
"requirements": ["pyatmo==8.0.0"]
|
||||
}
|
||||
|
@ -447,17 +447,16 @@ class NetatmoWeatherSensor(NetatmoBase, SensorEntity):
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return entity availability."""
|
||||
return self.state is not None
|
||||
|
||||
@callback
|
||||
def async_update_callback(self) -> None:
|
||||
"""Update the entity's state."""
|
||||
if (
|
||||
state := getattr(self._module, self.entity_description.netatmo_name)
|
||||
) is None:
|
||||
not self._module.reachable
|
||||
or (state := getattr(self._module, self.entity_description.netatmo_name))
|
||||
is None
|
||||
):
|
||||
if self.available:
|
||||
self._attr_available = False
|
||||
return
|
||||
|
||||
if self.entity_description.netatmo_name in {
|
||||
@ -475,6 +474,7 @@ class NetatmoWeatherSensor(NetatmoBase, SensorEntity):
|
||||
else:
|
||||
self._attr_native_value = state
|
||||
|
||||
self._attr_available = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
@ -519,7 +519,6 @@ class NetatmoClimateBatterySensor(NetatmoBase, SensorEntity):
|
||||
if not self._module.reachable:
|
||||
if self.available:
|
||||
self._attr_available = False
|
||||
self._attr_native_value = None
|
||||
return
|
||||
|
||||
self._attr_available = True
|
||||
@ -565,9 +564,15 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
|
||||
@callback
|
||||
def async_update_callback(self) -> None:
|
||||
"""Update the entity's state."""
|
||||
if not self._module.reachable:
|
||||
if self.available:
|
||||
self._attr_available = False
|
||||
return
|
||||
|
||||
if (state := getattr(self._module, self.entity_description.key)) is None:
|
||||
return
|
||||
|
||||
self._attr_available = True
|
||||
self._attr_native_value = state
|
||||
|
||||
self.async_write_ha_state()
|
||||
@ -777,7 +782,6 @@ class NetatmoPublicSensor(NetatmoBase, SensorEntity):
|
||||
self.entity_description.key,
|
||||
self._area_name,
|
||||
)
|
||||
self._attr_native_value = None
|
||||
|
||||
self._attr_available = False
|
||||
return
|
||||
|
@ -1637,7 +1637,7 @@ pyasuswrt==0.1.21
|
||||
pyatag==0.3.5.3
|
||||
|
||||
# homeassistant.components.netatmo
|
||||
pyatmo==7.6.0
|
||||
pyatmo==8.0.0
|
||||
|
||||
# homeassistant.components.apple_tv
|
||||
pyatv==0.14.3
|
||||
|
@ -1253,7 +1253,7 @@ pyasuswrt==0.1.21
|
||||
pyatag==0.3.5.3
|
||||
|
||||
# homeassistant.components.netatmo
|
||||
pyatmo==7.6.0
|
||||
pyatmo==8.0.0
|
||||
|
||||
# homeassistant.components.apple_tv
|
||||
pyatv==0.14.3
|
||||
|
@ -475,22 +475,12 @@
|
||||
"last_setup": 1558709954,
|
||||
"data_type": ["Temperature", "Humidity"],
|
||||
"battery_percent": 27,
|
||||
"reachable": true,
|
||||
"reachable": false,
|
||||
"firmware": 50,
|
||||
"last_message": 1644582699,
|
||||
"last_seen": 1644582699,
|
||||
"rf_status": 68,
|
||||
"battery_vp": 4678,
|
||||
"dashboard_data": {
|
||||
"time_utc": 1644582648,
|
||||
"Temperature": 9.4,
|
||||
"Humidity": 57,
|
||||
"min_temp": 6.7,
|
||||
"max_temp": 9.8,
|
||||
"date_max_temp": 1644534223,
|
||||
"date_min_temp": 1644569369,
|
||||
"temp_trend": "up"
|
||||
}
|
||||
"battery_vp": 4678
|
||||
},
|
||||
{
|
||||
"_id": "12:34:56:80:c1:ea",
|
||||
|
@ -561,26 +561,28 @@
|
||||
'access_doorbell',
|
||||
'access_presence',
|
||||
'read_bubendorff',
|
||||
'read_bfi',
|
||||
'read_camera',
|
||||
'read_carbonmonoxidedetector',
|
||||
'read_doorbell',
|
||||
'read_homecoach',
|
||||
'read_magellan',
|
||||
'read_mhs1',
|
||||
'read_mx',
|
||||
'read_presence',
|
||||
'read_smarther',
|
||||
'read_smokedetector',
|
||||
'read_station',
|
||||
'read_thermostat',
|
||||
'read_mhs1',
|
||||
'write_bubendorff',
|
||||
'write_bfi',
|
||||
'write_camera',
|
||||
'write_magellan',
|
||||
'write_mhs1',
|
||||
'write_mx',
|
||||
'write_presence',
|
||||
'write_smarther',
|
||||
'write_thermostat',
|
||||
'write_mhs1',
|
||||
]),
|
||||
'type': 'Bearer',
|
||||
}),
|
||||
|
@ -10,8 +10,8 @@ from homeassistant.helpers import entity_registry as er
|
||||
from .common import TEST_TIME, selected_platforms
|
||||
|
||||
|
||||
async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||
"""Test weather sensor setup."""
|
||||
async def test_indoor_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||
"""Test indoor sensor setup."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
@ -25,6 +25,18 @@ async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -
|
||||
assert hass.states.get(f"{prefix}pressure").state == "1014.5"
|
||||
|
||||
|
||||
async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||
"""Test weather sensor unreachable."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
prefix = "sensor.villa_outdoor_"
|
||||
|
||||
assert hass.states.get(f"{prefix}temperature").state == "unavailable"
|
||||
|
||||
|
||||
async def test_public_weather_sensor(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user