core/tests/components/shelly
J. Nick Koston df82567356
Fix shelly available check when device is not initialized (#124182)
* Fix shelly available check when device is not initialized

available needs to check for device.initialized or if the device
is sleepy as calls to status will raise NotInitialized which results
in many unretrieved exceptions while writing state

fixes
```
2024-08-18 09:33:03.757 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 453, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/config/custom_components/shelly/entity.py", line 374, in _update_callback
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1067, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1011, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 293, in state
    if (is_on := self.is_on) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/shelly/binary_sensor.py", line 331, in is_on
    return bool(self.attribute_value)
                ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/shelly/entity.py", line 545, in attribute_value
    self._last_value = self.sub_status
                       ^^^^^^^^^^^^^^^
  File "/config/custom_components/shelly/entity.py", line 534, in sub_status
    return self.status[self.entity_description.sub_key]
           ^^^^^^^^^^^
  File "/config/custom_components/shelly/entity.py", line 364, in status
    return cast(dict, self.coordinator.device.status[self.key])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 390, in status
    raise NotInitialized
aioshelly.exceptions.NotInitialized
```

* tweak

* cover

* fix

* cover

* fixes
2024-08-22 16:14:45 +03:00
..
bluetooth
__init__.py
conftest.py Prevent connecting to a Shelly device that is already connected (#122105) 2024-07-18 15:27:03 -05:00
test_binary_sensor.py Prevent connecting to a Shelly device that is already connected (#122105) 2024-07-18 15:27:03 -05:00
test_button.py
test_climate.py
test_config_flow.py Ignore Shelly IPv6 address in zeroconf (#123081) 2024-08-02 21:56:49 +03:00
test_coordinator.py Shelly RPC - do not stop BLE scanner if a sleeping device (#124147) 2024-08-18 18:35:02 +03:00
test_cover.py
test_device_trigger.py
test_diagnostics.py
test_event.py
test_init.py Prevent connecting to a Shelly device that is already connected (#122105) 2024-07-18 15:27:03 -05:00
test_light.py
test_logbook.py
test_number.py Add support for Shelly `number` virtual component (#121894) 2024-07-15 22:26:12 +02:00
test_select.py Add support for Shelly `enum` virtual component (#121997) 2024-07-18 17:55:14 +03:00
test_sensor.py Fix shelly available check when device is not initialized (#124182) 2024-08-22 16:14:45 +03:00
test_switch.py Use parametrize in tests for Shelly `boolean` virtual component (#121895) 2024-07-13 15:27:17 +03:00
test_text.py
test_update.py Prevent connecting to a Shelly device that is already connected (#122105) 2024-07-18 15:27:03 -05:00
test_utils.py Fix `configuration_url` for Shelly device using IPv6 (#121939) 2024-07-15 08:31:44 +02:00
test_valve.py