-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Update plugwise to async and config_flow #33691
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
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
ebb8a6b
Update plugwise async, config_flow and multi entity
CoMPaTech 3dbeb36
Update battery percentage
CoMPaTech 2504d0b
Fix yamllint on services
CoMPaTech 90b796b
Fix yamllint on services
CoMPaTech d0e5950
Fix formatting for pyupgrade
CoMPaTech 6c1e2c3
Update homeassistant/components/plugwise/__init__.py
CoMPaTech afd3c4d
Add try/except on setup
CoMPaTech 54ced3a
Bump module version, battery version and valve position
CoMPaTech cebbbfe
Removing sensor, switch, water_heater for later (child) PRs
CoMPaTech e3b6d91
Catchup and version bump
CoMPaTech d882b14
Remove title from strings.json
CoMPaTech fd4648d
Readd already reviewd await try/except
CoMPaTech db60de7
Readd already reviewed config_flow
CoMPaTech d1c2c05
Fix pylint
CoMPaTech ec74d9d
Fix per 0.109 translations
CoMPaTech fe1d2d3
Remove unused import from merge
CoMPaTech 132b17d
Translations and config_flow, module version bump with required changes
1276e97
Fix requirements
b716df4
Fix pylint
9d90fed
Update homeassistant/components/plugwise/__init__.py
CoMPaTech 1dba1fe
Update homeassistant/components/plugwise/__init__.py
CoMPaTech d457c94
Update homeassistant/components/plugwise/__init__.py
CoMPaTech 2ee78a5
Include configentrynotready on import
CoMPaTech e198002
Update __init__.py
CoMPaTech 43eb7b8
Update plugwise async, config_flow and multi entity
CoMPaTech 248ad61
Update battery percentage
CoMPaTech f615f23
Fix yamllint on services
CoMPaTech a5b1e0a
Fix yamllint on services
CoMPaTech 862a73b
Bump module version
CoMPaTech 166fb7b
Bump module version, battery version and valve position
CoMPaTech 96eeedb
Removing sensor, switch, water_heater for later (child) PRs
CoMPaTech ee63fe8
Catchup and version bump
CoMPaTech 8e9a761
Remove title from strings.json
CoMPaTech afa966d
Fix pylint
CoMPaTech cf85755
Fix per 0.109 translations
CoMPaTech 2038be2
Translations and config_flow, module version bump with required changes
6c9513f
Fix requirements
7de418b
Fix pylint
8e1f840
DataUpdateCoordinator and comment non-PR-platforms
605ddc7
Fix reqs
dcac991
Rename devices variable in favor of entities
928f581
Rework updates with DataUpdateCoordinator
ffd487e
Peer review
1af2f38
Peer review second part
0c71710
Cleanup comments and redundant code
2ca0684
Added required config_flow test
0c40b9c
Peer review third part
6e95aed
Update service was replaced by DataUpdateCoordinator
a42dd55
Corrected testing, version bump for InvalidAuth, move uniq_id
585a8f6
Remove according to review
e231ce8
Await connect (py38)
4acdcb6
Remove unneccesary code
756486c
Show only when multiple
20de695
Improve config_flow, rename consts
44ba32b
Update homeassistant/components/plugwise/climate.py
CoMPaTech d4631e8
Update homeassistant/components/plugwise/climate.py
CoMPaTech e65b0af
Process review comments
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 |
|---|---|---|
| @@ -1 +1,161 @@ | ||
| """Plugwise Climate (current only Anna) component for Home Assistant.""" | ||
| """Plugwise platform for Home Assistant Core.""" | ||
|
|
||
| import asyncio | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from Plugwise_Smile.Smile import Smile | ||
| import async_timeout | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.exceptions import ConfigEntryNotReady | ||
| from homeassistant.helpers import device_registry as dr | ||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
| from homeassistant.helpers.entity import Entity | ||
| from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| ALL_PLATFORMS = ["climate"] | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: dict): | ||
| """Set up the Plugwise platform.""" | ||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Set up Plugwise Smiles from a config entry.""" | ||
| websession = async_get_clientsession(hass, verify_ssl=False) | ||
| api = Smile( | ||
| host=entry.data["host"], password=entry.data["password"], websession=websession | ||
| ) | ||
|
|
||
| try: | ||
| connected = await api.connect() | ||
|
|
||
| if not connected: | ||
| _LOGGER.error("Unable to connect to Smile") | ||
| raise ConfigEntryNotReady | ||
|
|
||
| except Smile.InvalidAuthentication: | ||
| _LOGGER.error("Invalid Smile ID") | ||
| return False | ||
|
|
||
| except Smile.PlugwiseError: | ||
| _LOGGER.error("Error while communicating to device") | ||
| raise ConfigEntryNotReady | ||
|
|
||
| except asyncio.TimeoutError: | ||
| _LOGGER.error("Timeout while connecting to Smile") | ||
| raise ConfigEntryNotReady | ||
|
|
||
| if api.smile_type == "power": | ||
| update_interval = timedelta(seconds=10) | ||
| else: | ||
| update_interval = timedelta(seconds=60) | ||
|
|
||
| async def async_update_data(): | ||
| """Update data via API endpoint.""" | ||
| try: | ||
| async with async_timeout.timeout(10): | ||
| await api.full_update_device() | ||
| return True | ||
| except Smile.XMLDataMissingError: | ||
| raise UpdateFailed("Smile update failed") | ||
|
|
||
| coordinator = DataUpdateCoordinator( | ||
| hass, | ||
| _LOGGER, | ||
| name="Smile", | ||
| update_method=async_update_data, | ||
| update_interval=update_interval, | ||
| ) | ||
|
|
||
| await coordinator.async_refresh() | ||
|
|
||
| if not coordinator.last_update_success: | ||
| raise ConfigEntryNotReady | ||
|
|
||
| api.get_all_devices() | ||
|
bdraco marked this conversation as resolved.
|
||
|
|
||
| hass.data.setdefault(DOMAIN, {})[entry.entry_id] = { | ||
| "api": api, | ||
| "coordinator": coordinator, | ||
| } | ||
|
|
||
| device_registry = await dr.async_get_registry(hass) | ||
| device_registry.async_get_or_create( | ||
| config_entry_id=entry.entry_id, | ||
| identifiers={(DOMAIN, api.gateway_id)}, | ||
| manufacturer="Plugwise", | ||
| name=entry.title, | ||
| model=f"Smile {api.smile_name}", | ||
| sw_version=api.smile_version[0], | ||
| ) | ||
|
|
||
| for component in ALL_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): | ||
| """Unload a config entry.""" | ||
| unload_ok = all( | ||
| await asyncio.gather( | ||
| *[ | ||
| hass.config_entries.async_forward_entry_unload(entry, component) | ||
| for component in ALL_PLATFORMS | ||
| ] | ||
| ) | ||
| ) | ||
| if unload_ok: | ||
| hass.data[DOMAIN].pop(entry.entry_id) | ||
|
|
||
| return unload_ok | ||
|
|
||
|
|
||
| class SmileGateway(Entity): | ||
| """Represent Smile Gateway.""" | ||
|
|
||
| def __init__(self, api, coordinator): | ||
| """Initialise the sensor.""" | ||
| self._api = api | ||
| self._coordinator = coordinator | ||
| self._unique_id = None | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| """Return a unique ID.""" | ||
| return self._unique_id | ||
|
|
||
| @property | ||
| def should_poll(self): | ||
| """Return False, updates are controlled via coordinator.""" | ||
| return False | ||
|
|
||
| @property | ||
| def available(self): | ||
| """Return True if entity is available.""" | ||
| return self._coordinator.last_update_success | ||
|
|
||
| async def async_added_to_hass(self): | ||
| """Subscribe to updates.""" | ||
| self.async_on_remove(self._coordinator.async_add_listener(self._process_data)) | ||
|
|
||
| def _process_data(self): | ||
| """Interpret and process API data.""" | ||
| raise NotImplementedError | ||
|
|
||
| async def async_update(self): | ||
| """Update the entity.""" | ||
| await self._coordinator.async_request_refresh() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.