* Do not use a persistent connection to MPD
In other words, don't rely on the connection management provided by
"python-mpd2". Instead of keeping the connection to MPD open, we
explicitly connect before and disconnect after each command.
There is probably a bit of overhead to this, but as the integration
uses a local-polling approach to begin with, no functionality is lost or
degraded.
This change greatly hardens the MPD integration against both network
issues and problems with the daemon itself. All connection-related
failure modes have effectively been removed.
* Update state retrieval methods
Only "async_get_media_image" attempts to connect, all others are either
called from there, or from the main "async_update" method (see previous
commit) which also attempts to connect.
So, this commit mainly revolves around gracefully handling situations
where no connection is available when trying to retrieve MPD state.
Finally, note the removal of "self._commands". This property is only
used at the start of "_async_get_file_image_response" and was thus
changed into a local variable.
* Update media-player control methods
These all need to explicitly connect to MPD as part of their flow.
* Correct ruff failure (auto-fixed)
* Use "async_timeout.timeout" context manager
* Minor changes
* Replace "async_timeout" with "asyncio.timeout"
* Initialise "self._status" to empty dictionary
Used to be initialised as None, which caused "NoneType is not iterable"
type of issues in case of an unexpected disconnect (at which point
status gets set to None again). Instead of guarding against None
everywhere, using an empty dictionary seemed more prudent...
Furthermore, more cautiously access its members to prevent potential
KeyError-s in similar cases.
* Fix livelock in "async_mute_volume()"
This method doesn't need a connection; it calls into two other methods
that actually connect to MPD – attempting to connect from here resulted
in a livelock.
* Support HTTPS connections to Huawei LTE devices
Not all devices support HTTPS, so we default to plain HTTP still.
Ones that do are very likely to have certificates that do not pass
hostname verification, and are either self signed or issued by an
untrusted CA. Add option to use unverified HTTPS to make it possible to
connect to these, and when in effect, filter urllib3's related warnings
about insecure connections to the hostname in question.
* Use common config key and strings for certificate verification settings
Even though the wording might be slightly suboptimal here, it's better
to be consistent across the codebase than to finetune on this level.
This also switches the default the other way around: verification is
now disabled by default. This is not a good general default, but for
this particular case setups where the verification would succeed would
be so rare and require considerable local setup that it's very
unlikely to happen in practice.
* Add config flow tests
* Mock logout for better test coverage
* Set up custom requests session only when using unverified https
* Add https config flow test case
* Make better use of verify SSL default
* Repair duplicate devices added to the rainbird integration
* Apply suggestions from code review
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* Update tests/components/rainbird/test_init.py
* Remove use of config_entry.async_setup
---------
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* optionally decouple `EntityDescription.key` from API response key
this makes it possible to have multiple entities for a single API response field
* Add optional `value_fn` to EntityDescriptions
eg. to be able to map a API response value to a different value (status_code -> message)
* Add inverter `status_message` entity
* Add meter `meter_location_description` entity
* add external battery state
* Make Ohmpilot entity state translateable
* use built-in StrEnum
* test coverage
* remove unnecessary checks
None is handled before