Skip to content

Commit

Permalink
Merge pull request #90 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
tests improved
  • Loading branch information
grimmpp authored Mar 28, 2024
2 parents e52b294 + 2829d4b commit 1cb76c8
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 34 deletions.
51 changes: 25 additions & 26 deletions docs/service-send-message/eep-params.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Paramters for EEPs in Send Message Events
## Not Supported EEPs
* A5-09-0C
* A5-38-08
# 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/) from unit-test `TestSendMessageService` in file `./tests/test_send_message_service.py`).

## 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
* A5-06-01: day_light, illumination, twilight
* A5-07-01: learn_button, pir_status, pir_status_on, support_volrage_availability, support_voltage
* A5-08-01: illumination, learn_button, occupancy_button, pir_status, supply_voltage, temperature
* A5-10-06: current_temp, mode, stand_by, target_temp
* A5-10-12: current_temperature, humidity, target_temperature
* A5-12-01: data_type, divisor, learn_button, measurement_channel, meter_reading
* A5-12-02: data_type, divisor, learn_button, measurement_channel, meter_reading
* A5-12-03: data_type, divisor, learn_button, measurement_channel, meter_reading
* A5-13-01: dawn_sensor, day_night, hemisphere, identifier, learn_button, rain_indication, sun_east, sun_south, sun_west, temperature, wind_speed
* D5-00-01: contact, learn_button
* F6-02-01: energy_bow, rocker_first_action, rocker_second_action, second_action
* F6-02-02: energy_bow, rocker_first_action, rocker_second_action, second_action
* F6-10-00: handle_position, movement
* G5-3F-7F: direction, state, time
* H5-3F-7F: command, learn_button, time
* M5-38-08: state
## Not Supported EEPs
* `A5-09-0C`
* `A5-38-08`

## References:
Implementation of EEPs can be found [eltako14bus library](https://github.com/grimmpp/eltako14bus/blob/master/eltakobus/eep.py).
## 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
* `A5-06-01`: day_light, illumination, twilight
* `A5-07-01`: learn_button, pir_status, pir_status_on, support_volrage_availability, support_voltage
* `A5-08-01`: illumination, learn_button, occupancy_button, pir_status, supply_voltage, temperature
* `A5-10-06`: current_temp, mode, stand_by, target_temp
* `A5-10-12`: current_temperature, humidity, target_temperature
* `A5-12-01`: data_type, divisor, learn_button, measurement_channel, meter_reading
* `A5-12-02`: data_type, divisor, learn_button, measurement_channel, meter_reading
* `A5-12-03`: data_type, divisor, learn_button, measurement_channel, meter_reading
* `A5-13-01`: dawn_sensor, day_night, hemisphere, identifier, learn_button, rain_indication, sun_east, sun_south, sun_west, temperature, wind_speed
* `D5-00-01`: contact, learn_button
* `F6-02-01`: energy_bow, rocker_first_action, rocker_second_action, second_action
* `F6-02-02`: energy_bow, rocker_first_action, rocker_second_action, second_action
* `F6-10-00`: handle_position, movement
* `G5-3F-7F`: direction, state, time
* `H5-3F-7F`: command, learn_button, time
* `M5-38-08`: state
79 changes: 79 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import sys
import unittest
import json
import site

class MetadataTest(unittest.TestCase):

def get_site_package_folder(self):
for f in site.getsitepackages():
if 'site-packages' in f:
return f

def find_lib_folder(self, lib_name:str):
dirs = [f for f in os.listdir(self.get_site_package_folder()) if f.startswith(lib_name.replace('-', '_')+'-')]
if len(dirs) == 1:
return os.path.join(self.get_site_package_folder(), dirs[0])
return None

def get_installed_lib_version(self, lib_name:str):

dir_name = self.find_lib_folder(lib_name)
if dir_name:
metadata_file = os.path.join(dir_name, 'METADATA')
with open(metadata_file, 'r') as f:
for l in f.readlines():
if l.startswith('Version: '):
return l.replace('Version: ', '').strip()
return None
return None

def get_version_of_installed_eltako14bus(self):
return self.get_installed_lib_version('eltako14bus')

def get_manifest(self):
manifest_filename = os.path.join(os.getcwd(), 'custom_components', 'eltako', 'manifest.json')
with open(manifest_filename, 'r') as f:
return json.loads( f.read() )

def get_version_of_required_eltako14bus(self):
manifest = self.get_manifest()

for r in manifest['requirements']:
if r.startswith('eltako14bus'):
return r.split('==')[1].strip()
return None

def get_version_of_eltako_integration(self):
return self.get_manifest()['version']

def test_check_all_installed_dependencies(self):
manifest = self.get_manifest()

for r in manifest['requirements']:
if '==' in r:
lib_name = r.split('==')[0].strip()
required_version = r.split('==')[1].strip()
installed_version = self.get_installed_lib_version(lib_name)

# if this test fails install specified libraries in manifest.json
self.assertEqual(required_version, installed_version)


return None

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)

def test_if_changes_are_documented(self):
changes_filename = os.path.join(os.getcwd(), 'changes.md')
with open(changes_filename, 'r', encoding="utf-8") as f:
changes_text = f.read()

self.assertTrue( f'## Version {self.get_version_of_eltako_integration()}' in changes_text )
24 changes: 16 additions & 8 deletions tests/test_send_message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from unittest import mock
from homeassistant.helpers import dispatcher
import inspect
import sys
import os
import json

from tests.test_metadata import MetadataTest

dispatcher.dispatcher_send = mock.Mock(return_value=None)

Expand Down Expand Up @@ -47,15 +52,21 @@ async def test_send_message(self):


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'

eltakobus_version = MetadataTest().get_version_of_installed_eltako14bus()
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 {eltakobus_version}](https://pypi.org/project/eltako14bus/) '
rel_filename = '.'+__file__.replace(os.getcwd(), "").replace("\\", "/")
text += f'from unit-test `{type(self).__name__}` in file `{rel_filename}`). \n'
text += '\n'

text += "## Not Supported EEPs \n"
for eep_name in self.NOT_SUPPORTED_EEPS:
text += f"* {eep_name}\n"
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 @@ -64,14 +75,11 @@ async def test_write_eep_params_to_docs_file(self):

sig = inspect.signature(EEP.find(eep_name).__init__)
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'
text += f"* `{eep_name}`: {', '.join(eep_init_args)}\n"

file='./docs/service-send-message/eep-params.md'
with open(file, 'w') as filetowrite:
filetowrite.write(text)



0 comments on commit 1cb76c8

Please sign in to comment.