mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Cache Astral object in moon integration, to use less CPU (#44012)
Creating an Astral() instance seems to be surprisingly expensive. This was previously being done in every update, taking a non-trivial proportion of the (actual) CPU used by HA, that is, ignoring sleep/wait/idle states like being blocked on epoll. This patch caches the Astral instance to avoid recomputing it regularly.
This commit is contained in:
parent
b4afef1395
commit
2bbe8e0e6b
@ -49,6 +49,7 @@ class MoonSensor(Entity):
|
||||
"""Initialize the moon sensor."""
|
||||
self._name = name
|
||||
self._state = None
|
||||
self._astral = Astral()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@ -87,4 +88,4 @@ class MoonSensor(Entity):
|
||||
async def async_update(self):
|
||||
"""Get the time and updates the states."""
|
||||
today = dt_util.as_local(dt_util.utcnow()).date()
|
||||
self._state = Astral().moon_phase(today)
|
||||
self._state = self._astral.moon_phase(today)
|
||||
|
Loading…
x
Reference in New Issue
Block a user