Add configuration_url and entity_category to Fritz (#58004)

This commit is contained in:
Simone Chemelli 2021-10-19 04:30:45 +02:00 committed by GitHub
parent 1904019b5f
commit 1a978662ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View File

@ -11,6 +11,7 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -25,16 +26,19 @@ SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
key="is_connected", key="is_connected",
name="Connection", name="Connection",
device_class=DEVICE_CLASS_CONNECTIVITY, device_class=DEVICE_CLASS_CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="is_linked", key="is_linked",
name="Link", name="Link",
device_class=DEVICE_CLASS_PLUG, device_class=DEVICE_CLASS_PLUG,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="firmware_update", key="firmware_update",
name="Firmware Update", name="Firmware Update",
device_class=DEVICE_CLASS_UPDATE, device_class=DEVICE_CLASS_UPDATE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
) )

View File

@ -487,4 +487,5 @@ class FritzBoxBaseEntity:
"manufacturer": "AVM", "manufacturer": "AVM",
"model": self._fritzbox_tools.model, "model": self._fritzbox_tools.model,
"sw_version": self._fritzbox_tools.current_firmware, "sw_version": self._fritzbox_tools.current_firmware,
"configuration_url": f"http://{self._fritzbox_tools.host}",
} }

View File

@ -27,6 +27,8 @@ from homeassistant.const import (
DATA_RATE_KILOBITS_PER_SECOND, DATA_RATE_KILOBITS_PER_SECOND,
DATA_RATE_KILOBYTES_PER_SECOND, DATA_RATE_KILOBYTES_PER_SECOND,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -165,12 +167,14 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
key="device_uptime", key="device_uptime",
name="Device Uptime", name="Device Uptime",
device_class=DEVICE_CLASS_TIMESTAMP, device_class=DEVICE_CLASS_TIMESTAMP,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
value_fn=_retrieve_device_uptime_state, value_fn=_retrieve_device_uptime_state,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="connection_uptime", key="connection_uptime",
name="Connection Uptime", name="Connection Uptime",
device_class=DEVICE_CLASS_TIMESTAMP, device_class=DEVICE_CLASS_TIMESTAMP,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
value_fn=_retrieve_connection_uptime_state, value_fn=_retrieve_connection_uptime_state,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
@ -194,6 +198,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
name="Max Connection Upload Throughput", name="Max Connection Upload Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND, native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
icon="mdi:upload", icon="mdi:upload",
entity_category=ENTITY_CATEGORY_CONFIG,
value_fn=_retrieve_max_kb_s_sent_state, value_fn=_retrieve_max_kb_s_sent_state,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
@ -201,6 +206,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
name="Max Connection Download Throughput", name="Max Connection Download Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND, native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
icon="mdi:download", icon="mdi:download",
entity_category=ENTITY_CATEGORY_CONFIG,
value_fn=_retrieve_max_kb_s_received_state, value_fn=_retrieve_max_kb_s_received_state,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(

View File

@ -18,6 +18,7 @@ import xmltodict
from homeassistant.components.network import async_get_source_ip from homeassistant.components.network import async_get_source_ip
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -441,6 +442,7 @@ class FritzBoxPortSwitch(FritzBoxBaseSwitch, SwitchEntity):
self.connection_type = connection_type self.connection_type = connection_type
self.port_mapping = port_mapping # dict in the format as it comes from fritzconnection. eg: {'NewRemoteHost': '0.0.0.0', 'NewExternalPort': 22, 'NewProtocol': 'TCP', 'NewInternalPort': 22, 'NewInternalClient': '192.168.178.31', 'NewEnabled': True, 'NewPortMappingDescription': 'Beast SSH ', 'NewLeaseDuration': 0} self.port_mapping = port_mapping # dict in the format as it comes from fritzconnection. eg: {'NewRemoteHost': '0.0.0.0', 'NewExternalPort': 22, 'NewProtocol': 'TCP', 'NewInternalPort': 22, 'NewInternalClient': '192.168.178.31', 'NewEnabled': True, 'NewPortMappingDescription': 'Beast SSH ', 'NewLeaseDuration': 0}
self._idx = idx # needed for update routine self._idx = idx # needed for update routine
self._attr_entity_category = ENTITY_CATEGORY_CONFIG
if port_mapping is None: if port_mapping is None:
return return
@ -519,6 +521,7 @@ class FritzBoxDeflectionSwitch(FritzBoxBaseSwitch, SwitchEntity):
self.dict_of_deflection = dict_of_deflection self.dict_of_deflection = dict_of_deflection
self._attributes = {} self._attributes = {}
self.id = int(self.dict_of_deflection["DeflectionId"]) self.id = int(self.dict_of_deflection["DeflectionId"])
self._attr_entity_category = ENTITY_CATEGORY_CONFIG
switch_info = SwitchInfo( switch_info = SwitchInfo(
description=f"Call deflection {self.id}", description=f"Call deflection {self.id}",
@ -588,6 +591,7 @@ class FritzBoxProfileSwitch(FritzDeviceBase, SwitchEntity):
self._attr_is_on: bool = False self._attr_is_on: bool = False
self._name = f"{device.hostname} Internet Access" self._name = f"{device.hostname} Internet Access"
self._attr_unique_id = f"{self._mac}_internet_access" self._attr_unique_id = f"{self._mac}_internet_access"
self._attr_entity_category = ENTITY_CATEGORY_CONFIG
async def async_process_update(self) -> None: async def async_process_update(self) -> None:
"""Update device.""" """Update device."""