Skip to content

Commit

Permalink
Fix high load
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Mamontov committed Feb 8, 2022
1 parent 141d0e9 commit 7940fae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions custom_components/ledfx/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,20 @@ def entities(self) -> dict:

@property
def md5(self) -> str:
return hashlib.md5(
json.dumps({
"id": self._id,
"name": self._name,
"version": self._version,
"model": self._model,
"effects": dict(self._effects) if self._effects is not None else None,
"is_available": self._is_available,
"entities_data": self._entities_data,
"effect_properties": self._effect_properties,
"last_effect": dict(self._last_effect) if self._last_effect is not None else None
}).encode('utf-8')
).hexdigest()
return hashlib.md5(self.to_json()).hexdigest()

def to_json(self) -> bytes:
return json.dumps({
"id": self._id,
"name": self._name,
"version": self._version,
"model": self._model,
"effects": dict(self._effects) if self._effects is not None else None,
"is_available": self._is_available,
"entities_data": self._entities_data,
"effect_properties": self._effect_properties,
"last_effect": dict(self._last_effect) if self._last_effect is not None else None
}).encode('utf-8')

async def async_update_available(self, is_available: bool) -> None:
self._is_available = is_available
Expand All @@ -130,9 +131,9 @@ async def async_append_entity(self, entity: Entity, options: dict = {}) -> None:
self._entities[entity.id] = entity

if entity.id in self._entities_data and "support_effects" in options:
options["support_effects"] = list(set(
options["support_effects"] = sorted(list(set(
self._entities_data[entity.id]["support_effects"] + options["support_effects"]
))
)))

self._entities_data[entity.id] = options

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ledfx/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "ledfx",
"name": "LedFx",
"version": "1.3.0",
"version": "1.3.1",
"documentation": "https://github.com/dmamontov/hass-ledfx",
"issue_tracker": "https://github.com/dmamontov/hass-ledfx/issues",
"config_flow": true,
Expand Down

0 comments on commit 7940fae

Please sign in to comment.