mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +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."""
|
"""Initialize the moon sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._astral = Astral()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -87,4 +88,4 @@ class MoonSensor(Entity):
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the time and updates the states."""
|
"""Get the time and updates the states."""
|
||||||
today = dt_util.as_local(dt_util.utcnow()).date()
|
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