-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Refactor Freebox : add config flow + temperature sensor + signal dispatch #30334
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
bramkragten
merged 45 commits into
home-assistant:dev
from
Quentame:freebox/config-flow
Mar 11, 2020
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
333b365
Add config flow to Freebox
Quentame 7f0be6d
Add manufacturer in device_tracker info
Quentame fbf4de9
Add device_info to sensor + switch
Quentame 16fcbd4
Add device_info: connections
Quentame eb542d8
Add config_flow test + update .coveragerc
Quentame 1b8eb6f
Typing
Quentame c16e63b
Add device_type icon
Quentame 6cbdd20
Remove one error log
Quentame 2225da6
Fix pylint
Quentame 28086a3
Add myself as CODEOWNER
Quentame 2222fac
Handle sync in one place
Quentame 3452eb7
Separate the Freebox[Router/Device/Sensor] from __init__.py
Quentame c8a7930
Make temperature sensors auto-discovered
Quentame c3a8dd6
Use device activity instead of reachablility for device_tracker
Quentame d970b7a
Add link step to config flow
Quentame 5b02613
Fix comment
Quentame b223056
Store token file in .storage
Quentame af4722c
Remove IP sensors + add Freebox router as a device with attrs : IPs, …
Quentame 1941916
Add sensor should_poll=False
Quentame 2b02a1f
Use config_entry.unique_id
Quentame 0223084
Test typing
Quentame 8a420cf
Handle devices with no name
Quentame 1dd3f02
None is the default for data
Quentame 8c56ac1
Add async_unload_entry with asyncio
Quentame b36d8dd
Add and use bunch of data size and rate related constants (#31781)
Quentame 746105c
Review
Quentame b48cf9d
Remove useless "already_configured" error string
Quentame 90716ed
Review : merge 2 device & 2 sensor classes
Quentame 1bb3e57
Entities from platforms
Quentame fd5091f
Fix unload + add device after setup + clean loggers
Quentame 41b1aac
async_add_entities True
Quentame 6c19898
Review
Quentame 275d221
Use pathlib + refactor get_api
Quentame 98ebe6d
device_tracker set + tests with CoroutineMock()
Quentame f9fd400
Removing active & reachable from tracker attrs
Quentame 6a20db7
Review
Quentame 4b2bd31
Fix pipeline
Quentame 53789be
typing
Quentame 0b2e7a4
typing
Quentame a1396c1
typing
Quentame a89d3b5
Raise ConfigEntryNotReady when HttpRequestError at setup
Quentame b22c2e3
Review
Quentame fa3f939
Multiple Freebox s
Quentame b3d67bf
Review: store sensors in router
Quentame ae6223c
Freebox: a sensor story
Quentame 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,26 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "already_configured": "Host already configured" | ||
| }, | ||
| "error": { | ||
| "connection_failed": "Failed to connect, please try again", | ||
| "register_failed": "Failed to register, please try again", | ||
| "unknown": "Unknown error: please retry later" | ||
| }, | ||
| "step": { | ||
| "link": { | ||
| "description": "Click \"Submit\", then touch the right arrow on the router to register Freebox with Home Assistant.\n\n", | ||
| "title": "Link Freebox router" | ||
| }, | ||
| "user": { | ||
| "data": { | ||
| "host": "Host", | ||
| "port": "Port" | ||
| }, | ||
| "title": "Freebox" | ||
| } | ||
| }, | ||
| "title": "Freebox" | ||
| } | ||
| } |
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,110 @@ | ||
| """Config flow to configure the Freebox integration.""" | ||
| import logging | ||
|
|
||
| from aiofreepybox.exceptions import AuthorizationError, HttpRequestError | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_HOST, CONF_PORT | ||
|
|
||
| from .const import DOMAIN # pylint: disable=unused-import | ||
| from .router import get_api | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL | ||
|
|
||
| def __init__(self): | ||
| """Initialize Freebox config flow.""" | ||
| self._host = None | ||
| self._port = None | ||
|
|
||
| def _show_setup_form(self, user_input=None, errors=None): | ||
| """Show the setup form to the user.""" | ||
|
|
||
| if user_input is None: | ||
| user_input = {} | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Required(CONF_HOST, default=user_input.get(CONF_HOST, "")): str, | ||
| vol.Required(CONF_PORT, default=user_input.get(CONF_PORT, "")): int, | ||
| } | ||
| ), | ||
| errors=errors or {}, | ||
| ) | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle a flow initiated by the user.""" | ||
| errors = {} | ||
|
|
||
| if user_input is None: | ||
| return self._show_setup_form(user_input, errors) | ||
|
|
||
| self._host = user_input[CONF_HOST] | ||
| self._port = user_input[CONF_PORT] | ||
|
|
||
| # Check if already configured | ||
| await self.async_set_unique_id(self._host) | ||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
| self._abort_if_unique_id_configured() | ||
|
|
||
| return await self.async_step_link() | ||
|
|
||
| async def async_step_link(self, user_input=None): | ||
| """Attempt to link with the Freebox router. | ||
|
|
||
| Given a configured host, will ask the user to press the button | ||
| to connect to the router. | ||
| """ | ||
| if user_input is None: | ||
| return self.async_show_form(step_id="link") | ||
|
|
||
| errors = {} | ||
|
|
||
| fbx = await get_api(self.hass, self._host) | ||
| try: | ||
| # Open connection and check authentication | ||
| await fbx.open(self._host, self._port) | ||
|
|
||
| # Check permissions | ||
| await fbx.system.get_config() | ||
| await fbx.lan.get_hosts_list() | ||
| await self.hass.async_block_till_done() | ||
|
|
||
| # Close connection | ||
| await fbx.close() | ||
|
|
||
| return self.async_create_entry( | ||
| title=self._host, data={CONF_HOST: self._host, CONF_PORT: self._port}, | ||
|
Quentame marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| except AuthorizationError as error: | ||
| _LOGGER.error(error) | ||
| errors["base"] = "register_failed" | ||
|
|
||
| except HttpRequestError: | ||
| _LOGGER.error("Error connecting to the Freebox router at %s", self._host) | ||
| errors["base"] = "connection_failed" | ||
|
|
||
| except Exception: # pylint: disable=broad-except | ||
| _LOGGER.exception( | ||
| "Unknown error connecting with Freebox router at %s", self._host | ||
| ) | ||
| errors["base"] = "unknown" | ||
|
|
||
| return self.async_show_form(step_id="link", errors=errors) | ||
|
|
||
| async def async_step_import(self, user_input=None): | ||
| """Import a config entry.""" | ||
| return await self.async_step_user(user_input) | ||
|
|
||
| async def async_step_discovery(self, user_input=None): | ||
| """Initialize step from discovery.""" | ||
| return await self.async_step_user(user_input) | ||
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,75 @@ | ||
| """Freebox component constants.""" | ||
| import socket | ||
|
|
||
| from homeassistant.const import ( | ||
| DATA_RATE_KILOBYTES_PER_SECOND, | ||
| DEVICE_CLASS_TEMPERATURE, | ||
| TEMP_CELSIUS, | ||
| ) | ||
|
|
||
| DOMAIN = "freebox" | ||
|
|
||
| APP_DESC = { | ||
| "app_id": "hass", | ||
| "app_name": "Home Assistant", | ||
| "app_version": "0.106", | ||
| "device_name": socket.gethostname(), | ||
| } | ||
| API_VERSION = "v6" | ||
|
|
||
| PLATFORMS = ["device_tracker", "sensor", "switch"] | ||
|
|
||
| DEFAULT_DEVICE_NAME = "Unknown device" | ||
|
|
||
| # to store the cookie | ||
| STORAGE_KEY = DOMAIN | ||
| STORAGE_VERSION = 1 | ||
|
|
||
| # Sensor | ||
| SENSOR_NAME = "name" | ||
| SENSOR_UNIT = "unit" | ||
| SENSOR_ICON = "icon" | ||
| SENSOR_DEVICE_CLASS = "device_class" | ||
|
|
||
| CONNECTION_SENSORS = { | ||
| "rate_down": { | ||
| SENSOR_NAME: "Freebox download speed", | ||
| SENSOR_UNIT: DATA_RATE_KILOBYTES_PER_SECOND, | ||
| SENSOR_ICON: "mdi:download-network", | ||
| SENSOR_DEVICE_CLASS: None, | ||
| }, | ||
| "rate_up": { | ||
| SENSOR_NAME: "Freebox upload speed", | ||
| SENSOR_UNIT: DATA_RATE_KILOBYTES_PER_SECOND, | ||
| SENSOR_ICON: "mdi:upload-network", | ||
| SENSOR_DEVICE_CLASS: None, | ||
| }, | ||
| } | ||
|
|
||
| TEMPERATURE_SENSOR_TEMPLATE = { | ||
| SENSOR_NAME: None, | ||
| SENSOR_UNIT: TEMP_CELSIUS, | ||
| SENSOR_ICON: "mdi:thermometer", | ||
| SENSOR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, | ||
| } | ||
|
|
||
| # Icons | ||
| DEVICE_ICONS = { | ||
| "freebox_delta": "mdi:television-guide", | ||
| "freebox_hd": "mdi:television-guide", | ||
| "freebox_mini": "mdi:television-guide", | ||
| "freebox_player": "mdi:television-guide", | ||
| "ip_camera": "mdi:cctv", | ||
| "ip_phone": "mdi:phone-voip", | ||
| "laptop": "mdi:laptop", | ||
| "multimedia_device": "mdi:play-network", | ||
| "nas": "mdi:nas", | ||
| "networking_device": "mdi:network", | ||
| "printer": "mdi:printer", | ||
| "router": "mdi:router-wireless", | ||
| "smartphone": "mdi:cellphone", | ||
| "tablet": "mdi:tablet", | ||
| "television": "mdi:television", | ||
| "vg_console": "mdi:gamepad-variant", | ||
| "workstation": "mdi:desktop-tower-monitor", | ||
| } |
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.