core/homeassistant/components/fritz/sensor.py

321 lines
11 KiB
Python
Raw Normal View History

"""AVM FRITZ!Box binary sensors."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime, timedelta
import logging
from typing import Any
from fritzconnection.core.exceptions import FritzConnectionException
from fritzconnection.lib.fritzstatus import FritzStatus
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DATA_GIGABYTES,
2021-07-21 17:12:32 +00:00
DATA_RATE_KILOBITS_PER_SECOND,
DATA_RATE_KILOBYTES_PER_SECOND,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
SIGNAL_STRENGTH_DECIBELS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow
from .common import AvmWrapper, ConnectionInfo, FritzBoxBaseEntity
from .const import DOMAIN, DSL_CONNECTION, UPTIME_DEVIATION
_LOGGER = logging.getLogger(__name__)
def _uptime_calculation(seconds_uptime: float, last_value: datetime | None) -> datetime:
"""Calculate uptime with deviation."""
delta_uptime = utcnow() - timedelta(seconds=seconds_uptime)
if (
not last_value
or abs((delta_uptime - last_value).total_seconds()) > UPTIME_DEVIATION
):
return delta_uptime
return last_value
def _retrieve_device_uptime_state(
status: FritzStatus, last_value: datetime
) -> datetime:
"""Return uptime from device."""
return _uptime_calculation(status.device_uptime, last_value)
def _retrieve_connection_uptime_state(
status: FritzStatus, last_value: datetime | None
) -> datetime:
"""Return uptime from connection."""
return _uptime_calculation(status.connection_uptime, last_value)
def _retrieve_external_ip_state(status: FritzStatus, last_value: str) -> str:
"""Return external ip from device."""
return status.external_ip # type: ignore[no-any-return]
def _retrieve_kb_s_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload transmission rate."""
2021-08-04 19:53:07 +00:00
return round(status.transmission_rate[0] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_kb_s_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download transmission rate."""
2021-08-04 19:53:07 +00:00
return round(status.transmission_rate[1] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_max_kb_s_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload max transmission rate."""
2021-08-04 19:53:07 +00:00
return round(status.max_bit_rate[0] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_max_kb_s_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download max transmission rate."""
2021-08-04 19:53:07 +00:00
return round(status.max_bit_rate[1] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_gb_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload total data."""
2021-08-06 02:24:41 +00:00
return round(status.bytes_sent / 1000 / 1000 / 1000, 1) # type: ignore[no-any-return]
def _retrieve_gb_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download total data."""
2021-08-06 02:24:41 +00:00
return round(status.bytes_received / 1000 / 1000 / 1000, 1) # type: ignore[no-any-return]
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
def _retrieve_link_kb_s_sent_state(status: FritzStatus, last_value: str) -> float:
"""Return upload link rate."""
return round(status.max_linked_bit_rate[0] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_link_kb_s_received_state(status: FritzStatus, last_value: str) -> float:
"""Return download link rate."""
return round(status.max_linked_bit_rate[1] / 1000, 1) # type: ignore[no-any-return]
def _retrieve_link_noise_margin_sent_state(
status: FritzStatus, last_value: str
) -> float:
"""Return upload noise margin."""
return status.noise_margin[0] / 10 # type: ignore[no-any-return]
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
def _retrieve_link_noise_margin_received_state(
status: FritzStatus, last_value: str
) -> float:
"""Return download noise margin."""
return status.noise_margin[1] / 10 # type: ignore[no-any-return]
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
def _retrieve_link_attenuation_sent_state(
status: FritzStatus, last_value: str
) -> float:
"""Return upload line attenuation."""
return status.attenuation[0] / 10 # type: ignore[no-any-return]
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
def _retrieve_link_attenuation_received_state(
status: FritzStatus, last_value: str
) -> float:
"""Return download line attenuation."""
return status.attenuation[1] / 10 # type: ignore[no-any-return]
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
@dataclass
class FritzRequireKeysMixin:
"""Fritz sensor data class."""
value_fn: Callable[[FritzStatus, Any], Any]
@dataclass
class FritzSensorEntityDescription(SensorEntityDescription, FritzRequireKeysMixin):
"""Describes Fritz sensor entity."""
is_suitable: Callable[[ConnectionInfo], bool] = lambda info: info.wan_enabled
SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
FritzSensorEntityDescription(
key="external_ip",
name="External IP",
icon="mdi:earth",
value_fn=_retrieve_external_ip_state,
),
FritzSensorEntityDescription(
key="device_uptime",
name="Device Uptime",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_device_uptime_state,
is_suitable=lambda info: True,
),
FritzSensorEntityDescription(
key="connection_uptime",
name="Connection Uptime",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_connection_uptime_state,
),
FritzSensorEntityDescription(
key="kb_s_sent",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Upload Throughput",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:upload",
value_fn=_retrieve_kb_s_sent_state,
),
FritzSensorEntityDescription(
key="kb_s_received",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Download Throughput",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:download",
value_fn=_retrieve_kb_s_received_state,
),
FritzSensorEntityDescription(
key="max_kb_s_sent",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Max Connection Upload Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
icon="mdi:upload",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_max_kb_s_sent_state,
),
FritzSensorEntityDescription(
key="max_kb_s_received",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Max Connection Download Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
icon="mdi:download",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_max_kb_s_received_state,
),
FritzSensorEntityDescription(
key="gb_sent",
name="GB sent",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
icon="mdi:upload",
value_fn=_retrieve_gb_sent_state,
),
FritzSensorEntityDescription(
key="gb_received",
name="GB received",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
icon="mdi:download",
value_fn=_retrieve_gb_received_state,
),
FritzSensorEntityDescription(
key="link_kb_s_sent",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Upload Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:upload",
value_fn=_retrieve_link_kb_s_sent_state,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
FritzSensorEntityDescription(
key="link_kb_s_received",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Download Throughput",
native_unit_of_measurement=DATA_RATE_KILOBITS_PER_SECOND,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:download",
value_fn=_retrieve_link_kb_s_received_state,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
FritzSensorEntityDescription(
key="link_noise_margin_sent",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Upload Noise Margin",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:upload",
value_fn=_retrieve_link_noise_margin_sent_state,
is_suitable=lambda info: info.wan_enabled and info.connection == DSL_CONNECTION,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
FritzSensorEntityDescription(
key="link_noise_margin_received",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Download Noise Margin",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:download",
value_fn=_retrieve_link_noise_margin_received_state,
is_suitable=lambda info: info.wan_enabled and info.connection == DSL_CONNECTION,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
FritzSensorEntityDescription(
key="link_attenuation_sent",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Upload Power Attenuation",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:upload",
value_fn=_retrieve_link_attenuation_sent_state,
is_suitable=lambda info: info.wan_enabled and info.connection == DSL_CONNECTION,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
FritzSensorEntityDescription(
key="link_attenuation_received",
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
name="Link Download Power Attenuation",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
icon="mdi:download",
value_fn=_retrieve_link_attenuation_received_state,
is_suitable=lambda info: info.wan_enabled and info.connection == DSL_CONNECTION,
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
),
)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up entry."""
_LOGGER.debug("Setting up FRITZ!Box sensors")
avm_wrapper: AvmWrapper = hass.data[DOMAIN][entry.entry_id]
connection_info = await avm_wrapper.async_get_connection_info()
Add more Fritz sensors for DSL connections (#53198) * Update sensor.py Added information about the upstream line accorrding to fritzconnection library (available since V1.5.0) . New information available are line sync speed,, noise margin and power attenuation. Tested with ADSL and VDSL lines on fritzbox 7590, 7490 and 7390. Not tested on cable internet / fiber. According to upstrem library should also work / fail gracefully. * Update sensor.py Fixed errors from automated tests Sorry it took so long * Update homeassistant/components/fritz/sensor.py Thank you this sounds even better Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * Update homeassistant/components/fritz/sensor.py Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com> * black & mypy fixes * Rebase, fix multiplier, add conditional create Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2021-08-08 09:23:28 +00:00
entities = [
FritzBoxSensor(avm_wrapper, entry.title, description)
for description in SENSOR_TYPES
if description.is_suitable(connection_info)
]
async_add_entities(entities, True)
class FritzBoxSensor(FritzBoxBaseEntity, SensorEntity):
"""Define FRITZ!Box connectivity class."""
entity_description: FritzSensorEntityDescription
def __init__(
self,
avm_wrapper: AvmWrapper,
device_friendly_name: str,
description: FritzSensorEntityDescription,
) -> None:
"""Init FRITZ!Box connectivity class."""
self.entity_description = description
self._last_device_value: str | None = None
self._attr_available = True
self._attr_name = f"{device_friendly_name} {description.name}"
self._attr_unique_id = f"{avm_wrapper.unique_id}-{description.key}"
super().__init__(avm_wrapper, device_friendly_name)
def update(self) -> None:
"""Update data."""
_LOGGER.debug("Updating FRITZ!Box sensors")
status: FritzStatus = self._avm_wrapper.fritz_status
try:
self._attr_native_value = (
self._last_device_value
) = self.entity_description.value_fn(status, self._last_device_value)
except FritzConnectionException:
_LOGGER.error("Error getting the state from the FRITZ!Box", exc_info=True)
self._attr_available = False
return
self._attr_available = True