Skip to content

Commit

Permalink
Fix wrong parameter for CPU and json serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Oct 11, 2022
1 parent 79fd255 commit 4f97c66
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.3

- Fix wrong parameter for CPU [#70](https://github.com/elad-bar/ha-edgeos/issues/70)
- Another fix json serialization when saving debug data

## 2.0.2

- Fix json serialization when saving debug data
Expand Down
12 changes: 9 additions & 3 deletions custom_components/edgeos/component/api/storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ async def debug_log_ws(self, data: dict):
if self.store_debug_data and data is not None:
await self._storage_ws.async_save(self._get_json_data(data))

@staticmethod
def _get_json_data(data: dict):
json_data = json.dumps(data, default=lambda o: o.__dict__, sort_keys=True, indent=4)
def _get_json_data(self, data: dict):
json_data = json.dumps(data, default=self.json_converter, sort_keys=True, indent=4)

result = json.loads(json_data)

return result

@staticmethod
def json_converter(data):
if isinstance(data, datetime):
return data.__str__()
if isinstance(data, dict):
return data.__dict__
8 changes: 4 additions & 4 deletions custom_components/edgeos/component/managers/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ def _update_system_stats(self, system_stats_data: dict, discovery_data: dict):

uptime = float(system_stats_data.get(SYSTEM_STATS_DATA_UPTIME, 0))

system_data.cpu = int(system_stats_data.get(SYSTEM_STATS_DATA_CPU, 0))
system_data.mem = int(system_stats_data.get(SYSTEM_STATS_DATA_MEM, 0))

if uptime != system_data.uptime:
system_data.uptime = uptime
system_data.last_reset = self._get_last_reset(uptime)

system_data.cpu = int(system_stats_data.get(SYSTEM_STATS_DATA_CPU, 0))
system_data.mem = int(system_stats_data.get(SYSTEM_STATS_DATA_MEM, 0))

except Exception as ex:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno
Expand Down Expand Up @@ -693,7 +693,7 @@ def _load_cpu_sensor(self):
entity_name = f"{device_name} CPU Usage"

try:
state = self._system.leased_devices
state = self._system.cpu

leased_devices = []

Expand Down
2 changes: 1 addition & 1 deletion custom_components/edgeos/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"codeowners": ["@elad-bar"],
"requirements": ["aiohttp"],
"config_flow": true,
"version": "2.0.2",
"version": "2.0.3",
"iot_class": "local_polling"
}

0 comments on commit 4f97c66

Please sign in to comment.