-
-
Notifications
You must be signed in to change notification settings - Fork 37.9k
Add Home Connect integration #29214
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
Merged
Merged
Add Home Connect integration #29214
Changes from 42 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
95aca52
Initial commit for the Home Connect integrationq
DavidMStraub 1156161
Necessary changes in global files
DavidMStraub ddb2492
Correct homeconnect version number
DavidMStraub d177e5f
Fix unit test for homeconnect config flow
DavidMStraub fca5e1e
Fix pylint error
DavidMStraub 99fea5f
Fix failing unit test
DavidMStraub 8ac3fdf
Correct documentation links
DavidMStraub 9f96de5
Move import to top level
DavidMStraub 7218095
Limit try to single line
DavidMStraub cbd8b75
Expand doc strings
DavidMStraub 8f11c29
Move device list to ConfigEntryAuth property
DavidMStraub 7071bbf
Include fix to on/off switch
DavidMStraub 088e7d4
Bump homeconnect version to 0.3.2
DavidMStraub ce07c98
Use homeconnect 0.3.3
DavidMStraub 0aad963
Move device initialization out of init
DavidMStraub 61492c5
isort fixes
DavidMStraub 5d31710
Bump homeconnect version in requirements*.txt
DavidMStraub 5c46295
Additional coffee programs (https://github.com/DavidMStraub/homeassis…
DavidMStraub 35e155d
Bump homeconnect dependency
DavidMStraub c36fd86
Fix codespell typos
DavidMStraub f4f0913
Get rid of format_key
DavidMStraub deff55f
Allow multiple config entries
DavidMStraub ef71535
Fix pylint error
DavidMStraub c77a194
Bump homeconnect to 0.5
DavidMStraub ffc555f
Convert elapsed/remaining time to timestamp sensors
DavidMStraub 21c2131
Fix typo
DavidMStraub 405ec7c
Fix sign error
DavidMStraub 4c4c617
Fix JSON lint error
DavidMStraub 9fe20db
Remove elapsed program time sensor, fix for remaining program time
DavidMStraub 0efcdcb
Remove title from strings
DavidMStraub 9823f24
Fix remaining program timestamp sensor
DavidMStraub c83072a
Minor changes
DavidMStraub e417c5a
Move HomeConnectEntity to separate module
DavidMStraub 927ae8b
Remove state attributes
DavidMStraub 43ffb1a
Make turn_on/off async
DavidMStraub 80c3b5a
Put reused string constants into .const
DavidMStraub f7a4dac
Use dispatcher for updating entities
DavidMStraub 45a0147
Update homeassistant/components/homeconnect/entity.py
DavidMStraub 8c0ea15
Update homeassistant/components/homeconnect/entity.py
DavidMStraub fcb8e5e
Update homeassistant/components/homeconnect/entity.py
DavidMStraub eced930
Make door entity update async
DavidMStraub 6d9d626
Do not use device name in unique ID
DavidMStraub 6a93786
Rename power switch
DavidMStraub 8bd0f01
Rename method
DavidMStraub 266a0c4
Capitalize class attribute
DavidMStraub 9e7151e
Use BinarySensorEntity
DavidMStraub 53524c6
Explicit None not needed
DavidMStraub 697cd0e
Unneeded decorator
DavidMStraub cc29353
Rename integration to home_connect
DavidMStraub 105fc02
Use isoformat for timestamp sensor
DavidMStraub 658b036
Remove unneeded DEPENDENCIES
DavidMStraub 164b7a7
Do not store entities on device
DavidMStraub 3cb95c0
Update requirements_test_all.txt
DavidMStraub 36a0af8
Rename also test directory
DavidMStraub 338c50e
Typo
DavidMStraub a6cd1f4
Update homeassistant/components/home_connect/sensor.py
DavidMStraub 9acc067
Update homeassistant/components/home_connect/switch.py
DavidMStraub 0b656f6
Update homeassistant/components/home_connect/switch.py
DavidMStraub 875ef66
Update homeassistant/components/home_connect/switch.py
DavidMStraub 02a9045
Update homeassistant/components/home_connect/switch.py
DavidMStraub eefd0c5
Make update methods async
DavidMStraub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """Support for BSH Home Connect appliances.""" | ||
|
|
||
| import asyncio | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from requests import HTTPError | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv | ||
| from homeassistant.util import Throttle | ||
|
|
||
| from . import api, config_flow | ||
| from .const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| SCAN_INTERVAL = timedelta(minutes=1) | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema( | ||
| { | ||
| DOMAIN: vol.Schema( | ||
| { | ||
| vol.Required(CONF_CLIENT_ID): cv.string, | ||
| vol.Required(CONF_CLIENT_SECRET): cv.string, | ||
| } | ||
| ) | ||
| }, | ||
| extra=vol.ALLOW_EXTRA, | ||
| ) | ||
|
|
||
| PLATFORMS = ["binary_sensor", "sensor", "switch"] | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: dict) -> bool: | ||
| """Set up Home Connect component.""" | ||
| hass.data[DOMAIN] = {} | ||
|
|
||
| if DOMAIN not in config: | ||
| return True | ||
|
|
||
| config_flow.OAuth2FlowHandler.async_register_implementation( | ||
| hass, | ||
| config_entry_oauth2_flow.LocalOAuth2Implementation( | ||
| hass, | ||
| DOMAIN, | ||
| config[DOMAIN][CONF_CLIENT_ID], | ||
| config[DOMAIN][CONF_CLIENT_SECRET], | ||
| OAUTH2_AUTHORIZE, | ||
| OAUTH2_TOKEN, | ||
| ), | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Set up Home Connect from a config entry.""" | ||
| implementation = await config_entry_oauth2_flow.async_get_config_entry_implementation( | ||
| hass, entry | ||
| ) | ||
|
|
||
| hc_api = api.ConfigEntryAuth(hass, entry, implementation) | ||
|
|
||
| hass.data[DOMAIN][entry.entry_id] = hc_api | ||
|
|
||
| await update_all_devices(hass, entry) | ||
|
|
||
| for component in PLATFORMS: | ||
| hass.async_create_task( | ||
| hass.config_entries.async_forward_entry_setup(entry, component) | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| unload_ok = all( | ||
| await asyncio.gather( | ||
| *[ | ||
| hass.config_entries.async_forward_entry_unload(entry, component) | ||
| for component in PLATFORMS | ||
| ] | ||
| ) | ||
| ) | ||
| if unload_ok: | ||
| hass.data[DOMAIN].pop(entry.entry_id) | ||
|
|
||
| return unload_ok | ||
|
|
||
|
|
||
| @Throttle(SCAN_INTERVAL) | ||
| async def update_all_devices(hass, entry): | ||
| """Update all the devices.""" | ||
| data = hass.data[DOMAIN] | ||
| hc_api = data[entry.entry_id] | ||
| try: | ||
| await hass.async_add_executor_job(hc_api.get_devices) | ||
| for device_dict in hc_api.devices: | ||
| await hass.async_add_executor_job(device_dict["device"].initialize) | ||
| except HTTPError as err: | ||
| _LOGGER.warning("Cannot update devices: %s", err.response.status_code) | ||
|
springstan marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For initial contribution this is ok.
In the future, you might want to put this into a data class that sends a signal when new data is available. Now it can take a while before new data is adopted by entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the API doesn't push info about new devices. One has to query them and then listen to a separate SSE endpoint for each of them for state updates.
To be honest, I blatantly copied/adapted this function from Somfy without a very deep understanding 😬