Skip to content
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

Fix unreachable Netatmo sensor returning false values #105954

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/netatmo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"loggers": ["pyatmo"],
"requirements": ["pyatmo==7.6.0"]
"requirements": ["pyatmo==8.0.0"]
}
22 changes: 15 additions & 7 deletions homeassistant/components/netatmo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,17 @@ def __init__(
}
)

@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
self._attr_native_value = None
cgtobi marked this conversation as resolved.
Show resolved Hide resolved
return

if self.entity_description.netatmo_name in {
Expand All @@ -475,6 +475,7 @@ def async_update_callback(self) -> None:
else:
self._attr_native_value = state

self._attr_available = True
self.async_write_ha_state()


Expand Down Expand Up @@ -565,9 +566,16 @@ def __init__(
@callback
def async_update_callback(self) -> None:
"""Update the entity's state."""
if not self._module.reachable:
if self.available:
self._attr_available = False
self._attr_native_value = None
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()
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ pyasuswrt==0.1.20
pyatag==0.3.5.3

# homeassistant.components.netatmo
pyatmo==7.6.0
pyatmo==8.0.0

# homeassistant.components.apple_tv
pyatv==0.14.3
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ pyasuswrt==0.1.20
pyatag==0.3.5.3

# homeassistant.components.netatmo
pyatmo==7.6.0
pyatmo==8.0.0

# homeassistant.components.apple_tv
pyatv==0.14.3
Expand Down
14 changes: 2 additions & 12 deletions tests/components/netatmo/fixtures/getstationsdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions tests/components/netatmo/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down
16 changes: 14 additions & 2 deletions tests/components/netatmo/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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)

Expand All @@ -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:
Expand Down
Loading