🏡 Open source home automation that puts local control and privacy first.
Find a file
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
.devcontainer Update default pylint.importStrategy in dev container (#119900) 2024-06-19 11:27:01 +02:00
.github Drop ignore-missing-annotations from pylint tests (#120302) 2024-08-22 15:13:00 +02:00
.vscode Generate translation in vscode taks: Code Coverage (#120434) 2024-07-07 17:05:44 +02:00
homeassistant Fix shelly available check when device is not initialized (#124182) 2024-08-22 16:14:45 +03:00
machine Fix Raspberry Pi utilities installation on Alpine 3.19 (#110463) 2024-02-13 15:07:37 +01:00
pylint Update sensor recorder tests to async (#124061) 2024-08-18 13:20:58 -05:00
rootfs Stop the Home Assistant Core container by default (#101105) 2023-09-30 10:43:07 +02:00
script Bump dio-chacon-wifi-api to 1.2.1 (#124215) 2024-08-19 12:58:00 +02:00
tests Fix shelly available check when device is not initialized (#124182) 2024-08-22 16:14:45 +03:00
.core_files.yaml Update audit licenses run conditions [ci] (#123009) 2024-08-01 11:30:29 +02:00
.dockerignore Not to Tox (#76582) 2022-11-23 14:40:37 +01:00
.git-blame-ignore-revs Add ruff commit to git-blame-ignore-revs (#114229) 2024-03-26 12:16:55 +01:00
.gitattributes Ensure .pcm binary files do not have line endings changed (#91881) 2023-04-22 22:22:30 -04:00
.gitignore Add __pycache__ to gitignore (#114056) 2024-05-18 13:30:03 +02:00
.hadolint.yaml Update base image to 2023.10.0 (#102126) 2023-10-18 19:11:41 +02:00
.pre-commit-config.yaml Bump ruff to 0.6.1 (#124250) 2024-08-19 20:43:50 +02:00
.prettierignore Remove outdated prettier and yamllint azure-*.yml ignores (#112819) 2024-03-09 14:44:05 +02:00
.strict-typing Improve code quality in Manual alarm (#123142) 2024-08-18 21:31:44 +02:00
.yamllint Remove outdated prettier and yamllint azure-*.yml ignores (#112819) 2024-03-09 14:44:05 +02:00
build.yaml Update Home Assistant base image to 2024.06.1 (#120168) 2024-06-22 18:52:44 +02:00
CLA.md Update LICENSE.md and CLA.md to reflect the new Apache 2.0 license 2017-01-28 12:12:34 -08:00
CODE_OF_CONDUCT.md Update codespell to 2.3.0 (#118001) 2024-05-24 08:22:29 +02:00
codecov.yml Remove coveragerc (#121286) 2024-07-05 11:03:31 +02:00
CODEOWNERS New Integration: SMLIGHT SLZB-06 Adapters Integration (#118675) 2024-08-20 10:44:06 +02:00
CONTRIBUTING.md Use core GitHub URL in contributing guidelines (#41083) 2020-10-02 20:42:33 +02:00
Dockerfile Update uv to 0.2.27 (#122246) 2024-07-20 13:24:21 +02:00
Dockerfile.dev Use uv instead of pip in development env (#113517) 2024-05-21 09:56:31 +02:00
LICENSE.md Update license to official GitHub template (#16470) 2018-09-07 10:11:51 +02:00
MANIFEST.in Move remaining keys to setup.cfg (#65154) 2022-01-28 20:18:09 -08:00
mypy.ini Improve code quality in Manual alarm (#123142) 2024-08-18 21:31:44 +02:00
pyproject.toml Bump async-interrupt to 1.2.0 (#124360) 2024-08-21 16:59:41 +02:00
README.rst Add Open Home Foundation link (#116405) 2024-04-29 21:28:47 +02:00
requirements.txt Bump async-interrupt to 1.2.0 (#124360) 2024-08-21 16:59:41 +02:00
requirements_all.txt Bump pysmlight to 0.0.13 (#124398) 2024-08-22 12:04:03 +02:00
requirements_test.txt Update mypy-dev to 1.12.0a2 (#122613) 2024-07-25 21:48:10 +02:00
requirements_test_all.txt Bump pysmlight to 0.0.13 (#124398) 2024-08-22 12:04:03 +02:00
requirements_test_pre_commit.txt Bump ruff to 0.6.1 (#124250) 2024-08-19 20:43:50 +02:00

Home Assistant |Chat Status|
=================================================================================

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

Check out `home-assistant.io <https://home-assistant.io>`__ for `a
demo <https://demo.home-assistant.io>`__, `installation instructions <https://home-assistant.io/getting-started/>`__,
`tutorials <https://home-assistant.io/getting-started/automation/>`__ and `documentation <https://home-assistant.io/docs/>`__.

This is a project of the `Open Home Foundation <https://www.openhomefoundation.org/>`__.

|screenshot-states|

Featured integrations
---------------------

|screenshot-integrations|

The system is built using a modular approach so support for other devices or actions can be implemented easily. See also the `section on architecture <https://developers.home-assistant.io/docs/architecture_index/>`__ and the `section on creating your own
components <https://developers.home-assistant.io/docs/creating_component_index/>`__.

If you run into issues while using Home Assistant or during development
of a component, check the `Home Assistant help section <https://home-assistant.io/help/>`__ of our website for further help and information.

.. |Chat Status| image:: https://img.shields.io/discord/330944238910963714.svg
   :target: https://www.home-assistant.io/join-chat/
.. |screenshot-states| image:: https://raw.githubusercontent.com/home-assistant/core/dev/.github/assets/screenshot-states.png
   :target: https://demo.home-assistant.io
.. |screenshot-integrations| image:: https://raw.githubusercontent.com/home-assistant/core/dev/.github/assets/screenshot-integrations.png
   :target: https://home-assistant.io/integrations/