-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add config flow and device registry to fritzbox integration #31240
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
Changes from all commits
2f85e9d
0dec687
6414aee
3a9c02f
469213e
7a5788f
890504d
60e97cc
fb67cd9
8744184
999d28a
af95de9
0800e08
cb1ac6e
fbe1fbb
8bf9283
76d7112
8786b38
64ba364
60278ab
428ceba
cabe57f
16853b6
9a1a6cd
a62a725
431f230
48d24e6
e5304e2
1447914
47a8206
8ddf348
995632f
2cbea8c
18fca2a
26fb29c
f15511e
c39a81a
5187bac
c8cc9ee
9f8790d
e8a8341
d09df47
149a1f9
4e58bd8
7351aa7
bedd85d
fb76e58
ee282d3
c77410f
158c0cb
ec297cf
d94b588
7dd5027
ac7a8dc
5a797a0
4b848ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,24 @@ | ||
| """Support for Fritzbox binary sensors.""" | ||
| import logging | ||
|
|
||
| import requests | ||
|
|
||
| from homeassistant.components.binary_sensor import BinarySensorDevice | ||
| from homeassistant.const import CONF_DEVICES | ||
|
|
||
| from . import DOMAIN as FRITZBOX_DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| from .const import CONF_CONNECTIONS, DOMAIN as FRITZBOX_DOMAIN, LOGGER | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| """Set up the Fritzbox binary sensor platform.""" | ||
| devices = [] | ||
| fritz_list = hass.data[FRITZBOX_DOMAIN] | ||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For another PR we could consider consolidating the platform setup, since it's very similar for all platforms. The only things that change are the device |
||
| """Set up the Fritzbox binary sensor from config_entry.""" | ||
| entities = [] | ||
| devices = hass.data[FRITZBOX_DOMAIN][CONF_DEVICES] | ||
| fritz = hass.data[FRITZBOX_DOMAIN][CONF_CONNECTIONS][config_entry.entry_id] | ||
|
|
||
| for fritz in fritz_list: | ||
| device_list = fritz.get_devices() | ||
| for device in device_list: | ||
| if device.has_alarm: | ||
| devices.append(FritzboxBinarySensor(device, fritz)) | ||
| for device in await hass.async_add_executor_job(fritz.get_devices): | ||
| if device.has_alarm and device.ain not in devices: | ||
| entities.append(FritzboxBinarySensor(device, fritz)) | ||
| devices.add(device.ain) | ||
|
|
||
| add_entities(devices, True) | ||
| async_add_entities(entities, True) | ||
|
|
||
|
|
||
| class FritzboxBinarySensor(BinarySensorDevice): | ||
|
|
@@ -32,6 +29,22 @@ def __init__(self, device, fritz): | |
| self._device = device | ||
| self._fritz = fritz | ||
|
|
||
| @property | ||
| def device_info(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above about consolidation. In another PR we could create a common fritz entity base class that holds the common attributes. |
||
| """Return device specific attributes.""" | ||
| return { | ||
| "name": self.name, | ||
| "identifiers": {(FRITZBOX_DOMAIN, self._device.ain)}, | ||
| "manufacturer": self._device.manufacturer, | ||
| "model": self._device.productname, | ||
| "sw_version": self._device.fw_version, | ||
| } | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| """Return the unique ID of the device.""" | ||
| return self._device.ain | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the entity.""" | ||
|
|
@@ -54,5 +67,5 @@ def update(self): | |
| try: | ||
| self._device.update() | ||
| except requests.exceptions.HTTPError as ex: | ||
| _LOGGER.warning("Connection error: %s", ex) | ||
| LOGGER.warning("Connection error: %s", ex) | ||
| self._fritz.login() | ||
Uh oh!
There was an error while loading. Please reload this page.