mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Use new enums in fritz (#61446)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
44b7c0e65c
commit
80b65c679f
@ -4,15 +4,13 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_CONNECTIVITY,
|
BinarySensorDeviceClass,
|
||||||
DEVICE_CLASS_PLUG,
|
|
||||||
DEVICE_CLASS_UPDATE,
|
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
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 import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .common import FritzBoxBaseEntity, FritzBoxTools
|
from .common import FritzBoxBaseEntity, FritzBoxTools
|
||||||
@ -25,20 +23,20 @@ SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="is_connected",
|
key="is_connected",
|
||||||
name="Connection",
|
name="Connection",
|
||||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="is_linked",
|
key="is_linked",
|
||||||
name="Link",
|
name="Link",
|
||||||
device_class=DEVICE_CLASS_PLUG,
|
device_class=BinarySensorDeviceClass.PLUG,
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="firmware_update",
|
key="firmware_update",
|
||||||
name="Firmware Update",
|
name="Firmware Update",
|
||||||
device_class=DEVICE_CLASS_UPDATE,
|
device_class=BinarySensorDeviceClass.UPDATE,
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,21 +17,20 @@ from fritzconnection.core.exceptions import (
|
|||||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorDeviceClass,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DATA_GIGABYTES,
|
DATA_GIGABYTES,
|
||||||
DATA_RATE_KILOBITS_PER_SECOND,
|
DATA_RATE_KILOBITS_PER_SECOND,
|
||||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||||
DEVICE_CLASS_TIMESTAMP,
|
|
||||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
|
||||||
SIGNAL_STRENGTH_DECIBELS,
|
SIGNAL_STRENGTH_DECIBELS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
@ -165,21 +164,21 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
|||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="device_uptime",
|
key="device_uptime",
|
||||||
name="Device Uptime",
|
name="Device Uptime",
|
||||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.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=SensorDeviceClass.TIMESTAMP,
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=_retrieve_connection_uptime_state,
|
value_fn=_retrieve_connection_uptime_state,
|
||||||
),
|
),
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="kb_s_sent",
|
key="kb_s_sent",
|
||||||
name="Upload Throughput",
|
name="Upload Throughput",
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
|
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
value_fn=_retrieve_kb_s_sent_state,
|
value_fn=_retrieve_kb_s_sent_state,
|
||||||
@ -187,7 +186,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
|||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="kb_s_received",
|
key="kb_s_received",
|
||||||
name="Download Throughput",
|
name="Download Throughput",
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
|
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
value_fn=_retrieve_kb_s_received_state,
|
value_fn=_retrieve_kb_s_received_state,
|
||||||
@ -197,7 +196,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_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=_retrieve_max_kb_s_sent_state,
|
value_fn=_retrieve_max_kb_s_sent_state,
|
||||||
),
|
),
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
@ -205,13 +204,13 @@ 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_DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=_retrieve_max_kb_s_received_state,
|
value_fn=_retrieve_max_kb_s_received_state,
|
||||||
),
|
),
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="gb_sent",
|
key="gb_sent",
|
||||||
name="GB sent",
|
name="GB sent",
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
native_unit_of_measurement=DATA_GIGABYTES,
|
native_unit_of_measurement=DATA_GIGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
value_fn=_retrieve_gb_sent_state,
|
value_fn=_retrieve_gb_sent_state,
|
||||||
@ -219,7 +218,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
|||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="gb_received",
|
key="gb_received",
|
||||||
name="GB received",
|
name="GB received",
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
native_unit_of_measurement=DATA_GIGABYTES,
|
native_unit_of_measurement=DATA_GIGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
value_fn=_retrieve_gb_received_state,
|
value_fn=_retrieve_gb_received_state,
|
||||||
|
@ -18,10 +18,9 @@ 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, EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
@ -445,7 +444,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
|
self._attr_entity_category = EntityCategory.CONFIG
|
||||||
|
|
||||||
if port_mapping is None:
|
if port_mapping is None:
|
||||||
return
|
return
|
||||||
@ -524,7 +523,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
|
self._attr_entity_category = EntityCategory.CONFIG
|
||||||
|
|
||||||
switch_info = SwitchInfo(
|
switch_info = SwitchInfo(
|
||||||
description=f"Call deflection {self.id}",
|
description=f"Call deflection {self.id}",
|
||||||
@ -594,7 +593,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
|
self._attr_entity_category = EntityCategory.CONFIG
|
||||||
|
|
||||||
async def async_process_update(self) -> None:
|
async def async_process_update(self) -> None:
|
||||||
"""Update device."""
|
"""Update device."""
|
||||||
@ -655,7 +654,7 @@ class FritzBoxWifiSwitch(FritzBoxBaseSwitch, SwitchEntity):
|
|||||||
self._fritzbox_tools = fritzbox_tools
|
self._fritzbox_tools = fritzbox_tools
|
||||||
|
|
||||||
self._attributes = {}
|
self._attributes = {}
|
||||||
self._attr_entity_category = ENTITY_CATEGORY_CONFIG
|
self._attr_entity_category = EntityCategory.CONFIG
|
||||||
self._network_num = network_num
|
self._network_num = network_num
|
||||||
|
|
||||||
switch_info = SwitchInfo(
|
switch_info = SwitchInfo(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user