Skip to content

Commit

Permalink
added test for eltako14bus lib
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Mar 28, 2024
1 parent b0e1a67 commit a7a2788
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
9 changes: 4 additions & 5 deletions docs/service-send-message/eep-params.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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).
41 changes: 35 additions & 6 deletions tests/test_send_message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -45,17 +48,46 @@ 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"
for eep_name in self.NOT_SUPPORTED_EEPS:
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():

Expand All @@ -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)



0 comments on commit a7a2788

Please sign in to comment.