Skip to content

Commit

Permalink
remove deprecated constants
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Glenn Hansen <[email protected]>
  • Loading branch information
travisghansen committed Feb 16, 2024
1 parent 727db4a commit 65e9b62
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 55 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.6.3

Released 2024-02-16

- remove deprectated constants
- code formatting

# v0.6.2

Released 2024-02-16
Expand Down
9 changes: 5 additions & 4 deletions custom_components/pfsense/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for pfSense."""

from __future__ import annotations

import copy
Expand Down Expand Up @@ -398,10 +399,10 @@ def update(self, opts={}):
"used_percent"
] = cpu_used_percent
else:
new_state["telemetry"]["cpu"][
"used_percent"
] = dict_get(
previous_state, "telemetry.cpu.used_percent"
new_state["telemetry"]["cpu"]["used_percent"] = (
dict_get(
previous_state, "telemetry.cpu.used_percent"
)
)

for interface_name in dict_get(
Expand Down
1 change: 1 addition & 0 deletions custom_components/pfsense/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pfSense integration."""

import logging

from homeassistant.components.binary_sensor import (
Expand Down
1 change: 1 addition & 0 deletions custom_components/pfsense/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for pfSense integration."""

import logging
from urllib.parse import quote_plus, urlparse
import xmlrpc
Expand Down
67 changes: 34 additions & 33 deletions custom_components/pfsense/const.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""The pfSense component."""

from __future__ import annotations

from typing import Final

from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
SensorDeviceClass,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import (
DATA_BYTES,
FREQUENCY_HERTZ,
PERCENTAGE,
TEMP_CELSIUS,
TIME_SECONDS,
UnitOfFrequency,
UnitOfInformation,
UnitOfTemperature,
UnitOfTime,
)

DEFAULT_USERNAME = "admin"
Expand Down Expand Up @@ -53,7 +54,7 @@
PACKETS_RECEIVED = "packets_received"
PACKETS_SENT = "packets_sent"
DATA_PACKETS = "packets"
DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{TIME_SECONDS}"
DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{UnitOfTime.SECONDS}"

ICON_MEMORY = "mdi:memory"

Expand All @@ -64,7 +65,7 @@
name="pf State Table Used",
native_unit_of_measurement=COUNT,
icon="mdi:table-network",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.pfstate.total": SensorEntityDescription(
Expand All @@ -79,22 +80,22 @@
name="pf State Table Used Percentage",
native_unit_of_measurement=PERCENTAGE,
icon="mdi:table-network",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# mbuf
"telemetry.mbuf.used": SensorEntityDescription(
key="telemetry.mbuf.used",
name="Memory Buffers Used",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.mbuf.total": SensorEntityDescription(
key="telemetry.mbuf.total",
name="Memory Buffers Total",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
Expand All @@ -103,45 +104,45 @@
name="Memory Buffers Used Percentage",
native_unit_of_measurement=PERCENTAGE,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# memory with state_class due to being less static
"telemetry.memory.usermem": SensorEntityDescription(
key="telemetry.memory.usermem",
name="Memory Usermem",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.swap_reserved": SensorEntityDescription(
key="telemetry.memory.swap_reserved",
name="Memory Swap Reserved",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# memory without state_class due to being generally static
"telemetry.memory.physmem": SensorEntityDescription(
key="telemetry.memory.physmem",
name="Memory Physmem",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.realmem": SensorEntityDescription(
key="telemetry.memory.realmem",
name="Memory Realmem",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.swap_total": SensorEntityDescription(
key="telemetry.memory.swap_total",
name="Memory Swap Total",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
icon=ICON_MEMORY,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
Expand All @@ -151,15 +152,15 @@
name="Memory Swap Used Percentage",
native_unit_of_measurement=PERCENTAGE,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.memory.used_percent": SensorEntityDescription(
key="telemetry.memory.used_percent",
name="Memory Used Percentage",
native_unit_of_measurement=PERCENTAGE,
icon=ICON_MEMORY,
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# cpu
Expand All @@ -168,21 +169,21 @@
name="CPU Usage",
native_unit_of_measurement=PERCENTAGE,
icon="mdi:speedometer-medium",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.cpu.frequency.current": SensorEntityDescription(
key="telemetry.cpu.frequency.current",
name="CPU Frequency Current",
native_unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=UnitOfFrequency.HERTZ,
icon="mdi:speedometer-medium",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.cpu.frequency.max": SensorEntityDescription(
key="telemetry.cpu.frequency.max",
name="CPU Frequency Max",
native_unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=UnitOfFrequency.HERTZ,
icon="mdi:speedometer",
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
Expand All @@ -198,33 +199,33 @@
name="System Load Average One Minute",
# native_unit_of_measurement=PERCENTAGE,
icon="mdi:speedometer-slow",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.load_average.five_minute": SensorEntityDescription(
key="telemetry.system.load_average.five_minute",
name="System Load Average Five Minute",
# native_unit_of_measurement=PERCENTAGE,
icon="mdi:speedometer-slow",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.load_average.fifteen_minute": SensorEntityDescription(
key="telemetry.system.load_average.fifteen_minute",
name="System Load Average Fifteen Minute",
# native_unit_of_measurement=PERCENTAGE,
icon="mdi:speedometer-slow",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
# system
"telemetry.system.temp": SensorEntityDescription(
key="telemetry.system.temp",
name="System Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
icon="mdi:thermometer",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"telemetry.system.boottime": SensorEntityDescription(
Expand All @@ -241,23 +242,23 @@
name="DHCP Leases Total",
native_unit_of_measurement="clients",
icon="mdi:ip-network-outline",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"dhcp_stats.leases.online": SensorEntityDescription(
key="dhcp_stats.leases.online",
name="DHCP Leases Online",
native_unit_of_measurement="clients",
icon="mdi:ip-network-outline",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
"dhcp_stats.leases.idle_offline": SensorEntityDescription(
key="dhcp_stats.leases.idle_offline",
name="DHCP Leases Idle/Offline",
native_unit_of_measurement="clients",
icon="mdi:ip-network-outline",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
Expand Down
11 changes: 6 additions & 5 deletions custom_components/pfsense/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Support for tracking for pfSense devices."""

from __future__ import annotations

import logging
import time
from typing import Any, Mapping

from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
from homeassistant.components.device_tracker import SourceType
from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -191,7 +192,7 @@ def available(self) -> bool:
@property
def source_type(self) -> str:
"""Return the source type, eg gps or router, of the device."""
return SOURCE_TYPE_ROUTER
return SourceType.ROUTER

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
Expand All @@ -213,9 +214,9 @@ def _extra_state_attributes(self) -> Mapping[str, Any] | None:
self._extra_state["last_known_ip"] = self._last_known_ip

if self._last_known_connected_time is not None:
self._extra_state[
"last_known_connected_time"
] = self._last_known_connected_time
self._extra_state["last_known_connected_time"] = (
self._last_known_connected_time
)

return self._extra_state

Expand Down
Loading

0 comments on commit 65e9b62

Please sign in to comment.