From a7a27888caca4a4fc4d52a0fdda3c1dc617b1576 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Thu, 28 Mar 2024 21:36:11 +0100 Subject: [PATCH] added test for eltako14bus lib --- docs/service-send-message/eep-params.md | 9 +++--- tests/test_send_message_service.py | 41 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/service-send-message/eep-params.md b/docs/service-send-message/eep-params.md index 85babf46..29fa9546 100644 --- a/docs/service-send-message/eep-params.md +++ b/docs/service-send-message/eep-params.md @@ -1,9 +1,11 @@ -# Paramters for EEPs in Send Message Events +# Paramters for EEPs in Send Message Events +(This file was auto-generated by using [eltako14bus library](https://github.com/grimmpp/eltako14bus/blob/master/eltakobus/eep.py) in [version 0.0.49](https://pypi.org/project/eltako14bus/).) + ## Not Supported EEPs * A5-09-0C * A5-38-08 -## Parameters for events: +## Parameters for events * A5-04-01: humidity, learn_button, temp_availability, temperature * A5-04-02: humidity, learn_button, temperature * A5-04-03: humidity, learn_button, telegram_type, temperature @@ -23,6 +25,3 @@ * G5-3F-7F: direction, state, time * H5-3F-7F: command, learn_button, time * M5-38-08: state - -## References: -Implementation of EEPs can be found [eltako14bus library](https://github.com/grimmpp/eltako14bus/blob/master/eltakobus/eep.py). diff --git a/tests/test_send_message_service.py b/tests/test_send_message_service.py index 122b8916..a7745aa5 100644 --- a/tests/test_send_message_service.py +++ b/tests/test_send_message_service.py @@ -3,6 +3,9 @@ from unittest import mock from homeassistant.helpers import dispatcher import inspect +import sys +import os +import json dispatcher.dispatcher_send = mock.Mock(return_value=None) @@ -45,9 +48,38 @@ async def test_send_message(self): await g.async_service_send_message(event, True) + def get_version_of_installed_eltako14bus(self): + dirname = [f for f in os.listdir(os.path.join(sys.exec_prefix, 'Lib', 'site-packages')) if f.startswith('eltako14bus')][0] + metadata_file = os.path.join(sys.exec_prefix, 'Lib', 'site-packages', dirname, 'METADATA') + with open(metadata_file, 'r') as f: + for l in f.readlines(): + if l.startswith('Version: '): + return l.replace('Version: ', '').strip() + return None + + def get_version_of_required_eltako14bus(self): + manifest_filename = os.path.join(os.getcwd(), 'custom_components', 'eltako', 'manifest.json') + with open(manifest_filename, 'r') as f: + manifest = json.loads( f.read() ) + + for r in manifest['requirements']: + if r.startswith('eltako14bus'): + return r.split('==')[1].strip() + return None + + async def test_eltako14bus_required_and_installed_is_the_same(self): + installed = self.get_version_of_installed_eltako14bus() + required = self.get_version_of_required_eltako14bus() + + self.assertIsNotNone(installed) + self.assertIsNotNone(required) + self.assertEqual(installed, required) async def test_write_eep_params_to_docs_file(self): - text = '# Paramters for EEPs in Send Message Events' + text = '# Paramters for EEPs in Send Message Events \n' + + text += f'(This file was auto-generated by using [eltako14bus library](https://github.com/grimmpp/eltako14bus/blob/master/eltakobus/eep.py) ' + text += f'in [version {self.get_version_of_installed_eltako14bus()}](https://pypi.org/project/eltako14bus/).)\n' text += '\n' text += "## Not Supported EEPs \n" @@ -55,7 +87,7 @@ async def test_write_eep_params_to_docs_file(self): text += f"* {eep_name}\n" text += '\n' - text += '## Parameters for events: \n' + text += '## Parameters for events \n' for eep_name in self.get_all_eep_names(): @@ -66,12 +98,9 @@ async def test_write_eep_params_to_docs_file(self): eep_init_args = sorted([param.name for param in sig.parameters.values() if param.kind == param.POSITIONAL_OR_KEYWORD and param.name != 'self']) text += f"* {eep_name}: {', '.join(eep_init_args)}\n" - text += '\n' - text += '## References:\n' - text += 'Implementation of EEPs can be found [eltako14bus library](https://github.com/grimmpp/eltako14bus/blob/master/eltakobus/eep.py).\n' - file='./docs/service-send-message/eep-params.md' with open(file, 'w') as filetowrite: filetowrite.write(text) +