Skip to content

Commit

Permalink
Adopt Unit of Data & Information from HA Core
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Mar 2, 2023
1 parent 583fd30 commit c6d0ef6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 210 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.0.27

Configuration breaking change

- Adopt Unit of Data & Information from HA Core [#90](https://github.com/elad-bar/ha-edgeos/issues/90) [#84](https://github.com/elad-bar/ha-edgeos/issues/84)

Changing the units will be available per entity instead of maintaining it with select component, native unit is bytes - B (information) or B/s (traffic)

## 2.0.26

Configuration breaking change
Expand Down
16 changes: 0 additions & 16 deletions custom_components/edgeos/component/api/storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ...core.helpers.const import DOMAIN, STORAGE_VERSION
from ...core.helpers.enums import ConnectivityStatus
from ..helpers.const import (
ATTR_BYTE,
DEFAULT_CONSIDER_AWAY_INTERVAL,
DEFAULT_UPDATE_API_INTERVAL,
DEFAULT_UPDATE_ENTITIES_INTERVAL,
Expand All @@ -23,7 +22,6 @@
STORAGE_DATA_LOG_INCOMING_MESSAGES,
STORAGE_DATA_MONITORED_DEVICES,
STORAGE_DATA_MONITORED_INTERFACES,
STORAGE_DATA_UNIT,
STORAGE_DATA_UPDATE_API_INTERVAL,
STORAGE_DATA_UPDATE_ENTITIES_INTERVAL,
)
Expand Down Expand Up @@ -67,12 +65,6 @@ def monitored_devices(self):

return result

@property
def unit(self):
result = self.data.get(STORAGE_DATA_UNIT, ATTR_BYTE)

return result

@property
def log_incoming_messages(self):
result = self.data.get(STORAGE_DATA_LOG_INCOMING_MESSAGES, False)
Expand Down Expand Up @@ -135,7 +127,6 @@ async def _async_load_configuration(self):
self.data = {
STORAGE_DATA_MONITORED_INTERFACES: {},
STORAGE_DATA_MONITORED_DEVICES: {},
STORAGE_DATA_UNIT: ATTR_BYTE,
STORAGE_DATA_LOG_INCOMING_MESSAGES: False,
STORAGE_DATA_CONSIDER_AWAY_INTERVAL: DEFAULT_CONSIDER_AWAY_INTERVAL.total_seconds(),
STORAGE_DATA_UPDATE_ENTITIES_INTERVAL: DEFAULT_UPDATE_ENTITIES_INTERVAL.total_seconds(),
Expand Down Expand Up @@ -171,13 +162,6 @@ async def set_monitored_device(self, device_name: str, is_enabled: bool):

await self._async_save()

async def set_unit(self, unit: str):
_LOGGER.debug(f"Set unit to {unit}")

self.data[STORAGE_DATA_UNIT] = unit

await self._async_save()

async def set_log_incoming_messages(self, enabled: bool):
_LOGGER.debug(f"Set log incoming messages to {enabled}")

Expand Down
18 changes: 2 additions & 16 deletions custom_components/edgeos/component/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

STORAGE_DATA_MONITORED_INTERFACES = "monitored-interfaces"
STORAGE_DATA_MONITORED_DEVICES = "monitored-devices"
STORAGE_DATA_UNIT = "unit"
STORAGE_DATA_LOG_INCOMING_MESSAGES = "log-incoming-messages"
STORAGE_DATA_CONSIDER_AWAY_INTERVAL = "consider-away-interval"
STORAGE_DATA_UPDATE_ENTITIES_INTERVAL = "update-entities-interval"
Expand Down Expand Up @@ -72,10 +71,6 @@

INTERFACES_STATS = "stats"

BYTE = 1
KILO_BYTE = BYTE * 1024
MEGA_BYTE = KILO_BYTE * 1024

# CHANGE TO API DATA
API_DATA_DHCP_STATS = "dhcp_stats"
API_DATA_SYS_INFO = "sys_info"
Expand Down Expand Up @@ -114,12 +109,6 @@
SYSTEM_STATS_DATA_CPU = "cpu"
SYSTEM_STATS_DATA_MEM = "mem"

ATTR_BYTE = "B"
ATTR_KILO = "KB"
ATTR_MEGA = "MB"

UNIT_MAPPING = {ATTR_BYTE: BYTE, ATTR_KILO: KILO_BYTE, ATTR_MEGA: MEGA_BYTE}

DEVICE_LIST = "devices"
ADDRESS_LIST = "addresses"
FW_LATEST = "addresses"
Expand Down Expand Up @@ -270,9 +259,6 @@
vol.Optional(
STORAGE_DATA_LOG_INCOMING_MESSAGES.replace(STRING_DASH, STRING_UNDERSCORE)
): cv.boolean,
vol.Optional(STORAGE_DATA_UNIT.replace(STRING_DASH, STRING_UNDERSCORE)): vol.In(
UNIT_MAPPING.keys()
),
}
)

Expand Down Expand Up @@ -329,9 +315,9 @@
SENT_PACKETS_PREFIX: SENT_PACKETS_ICON,
}

STATS_RATE = [RECEIVED_RATE_PREFIX, SENT_RATE_PREFIX]
STATS_DATA_RATE = [RECEIVED_RATE_PREFIX, SENT_RATE_PREFIX]

STATS_TRAFFIC = [RECEIVED_TRAFFIC_PREFIX, SENT_TRAFFIC_PREFIX]
STATS_DATA_SIZE = [RECEIVED_TRAFFIC_PREFIX, SENT_TRAFFIC_PREFIX]

STATS_UNITS = {
RECEIVED_DROPPED_PREFIX: TRAFFIC_DATA_DROPPED,
Expand Down
Loading

0 comments on commit c6d0ef6

Please sign in to comment.