mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +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",
|
"integration_type": "hub",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pyatmo"],
|
"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
|
@callback
|
||||||
def async_update_callback(self) -> None:
|
def async_update_callback(self) -> None:
|
||||||
"""Update the entity's state."""
|
"""Update the entity's state."""
|
||||||
if (
|
if (
|
||||||
state := getattr(self._module, self.entity_description.netatmo_name)
|
not self._module.reachable
|
||||||
) is None:
|
or (state := getattr(self._module, self.entity_description.netatmo_name))
|
||||||
|
is None
|
||||||
|
):
|
||||||
|
if self.available:
|
||||||
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.entity_description.netatmo_name in {
|
if self.entity_description.netatmo_name in {
|
||||||
@ -475,6 +474,7 @@ class NetatmoWeatherSensor(NetatmoBase, SensorEntity):
|
|||||||
else:
|
else:
|
||||||
self._attr_native_value = state
|
self._attr_native_value = state
|
||||||
|
|
||||||
|
self._attr_available = True
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
@ -519,7 +519,6 @@ class NetatmoClimateBatterySensor(NetatmoBase, SensorEntity):
|
|||||||
if not self._module.reachable:
|
if not self._module.reachable:
|
||||||
if self.available:
|
if self.available:
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
self._attr_native_value = None
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
@ -565,9 +564,15 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_callback(self) -> None:
|
def async_update_callback(self) -> None:
|
||||||
"""Update the entity's state."""
|
"""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:
|
if (state := getattr(self._module, self.entity_description.key)) is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._attr_available = True
|
||||||
self._attr_native_value = state
|
self._attr_native_value = state
|
||||||
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
@ -777,7 +782,6 @@ class NetatmoPublicSensor(NetatmoBase, SensorEntity):
|
|||||||
self.entity_description.key,
|
self.entity_description.key,
|
||||||
self._area_name,
|
self._area_name,
|
||||||
)
|
)
|
||||||
self._attr_native_value = None
|
|
||||||
|
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
|
@ -1637,7 +1637,7 @@ pyasuswrt==0.1.21
|
|||||||
pyatag==0.3.5.3
|
pyatag==0.3.5.3
|
||||||
|
|
||||||
# homeassistant.components.netatmo
|
# homeassistant.components.netatmo
|
||||||
pyatmo==7.6.0
|
pyatmo==8.0.0
|
||||||
|
|
||||||
# homeassistant.components.apple_tv
|
# homeassistant.components.apple_tv
|
||||||
pyatv==0.14.3
|
pyatv==0.14.3
|
||||||
|
@ -1253,7 +1253,7 @@ pyasuswrt==0.1.21
|
|||||||
pyatag==0.3.5.3
|
pyatag==0.3.5.3
|
||||||
|
|
||||||
# homeassistant.components.netatmo
|
# homeassistant.components.netatmo
|
||||||
pyatmo==7.6.0
|
pyatmo==8.0.0
|
||||||
|
|
||||||
# homeassistant.components.apple_tv
|
# homeassistant.components.apple_tv
|
||||||
pyatv==0.14.3
|
pyatv==0.14.3
|
||||||
|
@ -475,22 +475,12 @@
|
|||||||
"last_setup": 1558709954,
|
"last_setup": 1558709954,
|
||||||
"data_type": ["Temperature", "Humidity"],
|
"data_type": ["Temperature", "Humidity"],
|
||||||
"battery_percent": 27,
|
"battery_percent": 27,
|
||||||
"reachable": true,
|
"reachable": false,
|
||||||
"firmware": 50,
|
"firmware": 50,
|
||||||
"last_message": 1644582699,
|
"last_message": 1644582699,
|
||||||
"last_seen": 1644582699,
|
"last_seen": 1644582699,
|
||||||
"rf_status": 68,
|
"rf_status": 68,
|
||||||
"battery_vp": 4678,
|
"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"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_id": "12:34:56:80:c1:ea",
|
"_id": "12:34:56:80:c1:ea",
|
||||||
|
@ -561,26 +561,28 @@
|
|||||||
'access_doorbell',
|
'access_doorbell',
|
||||||
'access_presence',
|
'access_presence',
|
||||||
'read_bubendorff',
|
'read_bubendorff',
|
||||||
|
'read_bfi',
|
||||||
'read_camera',
|
'read_camera',
|
||||||
'read_carbonmonoxidedetector',
|
'read_carbonmonoxidedetector',
|
||||||
'read_doorbell',
|
'read_doorbell',
|
||||||
'read_homecoach',
|
'read_homecoach',
|
||||||
'read_magellan',
|
'read_magellan',
|
||||||
|
'read_mhs1',
|
||||||
'read_mx',
|
'read_mx',
|
||||||
'read_presence',
|
'read_presence',
|
||||||
'read_smarther',
|
'read_smarther',
|
||||||
'read_smokedetector',
|
'read_smokedetector',
|
||||||
'read_station',
|
'read_station',
|
||||||
'read_thermostat',
|
'read_thermostat',
|
||||||
'read_mhs1',
|
|
||||||
'write_bubendorff',
|
'write_bubendorff',
|
||||||
|
'write_bfi',
|
||||||
'write_camera',
|
'write_camera',
|
||||||
'write_magellan',
|
'write_magellan',
|
||||||
|
'write_mhs1',
|
||||||
'write_mx',
|
'write_mx',
|
||||||
'write_presence',
|
'write_presence',
|
||||||
'write_smarther',
|
'write_smarther',
|
||||||
'write_thermostat',
|
'write_thermostat',
|
||||||
'write_mhs1',
|
|
||||||
]),
|
]),
|
||||||
'type': 'Bearer',
|
'type': 'Bearer',
|
||||||
}),
|
}),
|
||||||
|
@ -10,8 +10,8 @@ from homeassistant.helpers import entity_registry as er
|
|||||||
from .common import TEST_TIME, selected_platforms
|
from .common import TEST_TIME, selected_platforms
|
||||||
|
|
||||||
|
|
||||||
async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
async def test_indoor_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||||
"""Test weather sensor setup."""
|
"""Test indoor sensor setup."""
|
||||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
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"
|
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(
|
async def test_public_weather_sensor(
|
||||||
hass: HomeAssistant, config_entry, netatmo_auth
|
hass: HomeAssistant, config_entry, netatmo_auth
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user