diff --git a/cherry/sun/__init__.py b/cherry/sun/__init__.py index 4167319..59e7372 100644 --- a/cherry/sun/__init__.py +++ b/cherry/sun/__init__.py @@ -23,6 +23,7 @@ from datetime import datetime import yaml from dns.asyncresolver import resolve from asyncio_mqtt import Client +import umsgpack from astral import LocationInfo from astral.location import Location @@ -30,7 +31,7 @@ from astral.location import Location from dateutil.tz import gettz -async def compute_rising(location): +async def compute_direction(location): """ Determines if the sun is rising or setting. @@ -103,9 +104,15 @@ async def update(config): logging.debug(f'Noon: {noon}') await client.publish('sun/noon', noon, retain=True) - rising = await compute_rising(location) - logging.debug(f'Rising: {rising}') - await client.publish('sun/rising', rising, retain=True) + direction = await compute_direction(location) + logging.debug(f'Direction: {direction}') + await client.publish('sun/direction', direction, retain=True) + + solar_state = {'elevation': elevation, + 'direction': direction, + 'noon': location.solar_elevation(location.noon())} + logging.debug(f'Solar State: {solar_state}') + await client.publish('sun/state', umsgpack.packb(solar_state), retain=True) sunrise = str(location.sunrise()) logging.debug(f'Sunrise: {sunrise}') diff --git a/requirements.txt b/requirements.txt index a48dc60..a2d9640 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ python-dateutil==2.8.1 pytz==2020.5 PyYAML==5.3.1 six==1.15.0 +u-msgpack-python==2.7.1 diff --git a/setup.py b/setup.py index 07ae662..cca752f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages setup(name='cherry-sun', - version='0.2', + version='0.3', description='Periodically publishes sun attributes to mqtt', author='Bob Carroll', author_email='bob.carroll@alum.rit.edu', @@ -11,6 +11,7 @@ setup(name='cherry-sun', 'pyyaml', 'dnspython', 'asyncio_mqtt', + 'u-msgpack-python', 'astral', 'python-dateutil'], classifiers=[