Skip to content

Commit

Permalink
cleanup, extended parameters so that in future we can not create file…
Browse files Browse the repository at this point in the history
…s for devices of plus that does not have plus
  • Loading branch information
pvyleta committed Mar 24, 2024
1 parent 92a0cfb commit 7a3de5a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
15 changes: 9 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from out import write_output, write_known_devices
from out import write_output, write_known_devices, write_dump
from converters import find_converters, device_to_name_current_to_name_param, converters_map
from sensor import get_dict_devices_sensor
from parameter import get_device_parameters
from command_ebus import get_commands_dict
from model import BaseObject, DeviceModel, VersionRange
from model import DeviceModel, VersionRange

# TODO Simplify output to less files by removing redundanc and extending parameter ranges
# TODO Simplify output to less files by removing redundancy and extending parameter ranges
# TODO Simplify output by joining params + sensors in one file per version range
# TODO Simplify output by removing plus/basic where they are identical and/or where there is no plus device (flairs etc)
# TODO add names of parameters parsed through the stringresources.de-de.xaml
# TODO go thorugh AirControlEBusCommands and figure out if flowMode can be set on the wall controller rather than on the unit

Expand Down Expand Up @@ -60,8 +62,8 @@
# By default, Fails only for DecentralAir70 for two parameters, where converters were added in newer version. That almost seems like omitment, so we just correct that when assigning converters, and keep this assert as a sanity check
# assert sensor in sensors
if sensor not in sensors:
# print(f"WARNING: Sensor {sensor} from previous version not present in version {sensor_version} for device {device_model.name}")
pass
# print(f"WARNING: Sensor {sensor} from previous version not present in version {sensor_version} for device {device_model.name}")

previous_sensors = sensors

Expand All @@ -70,10 +72,10 @@
for parameter_version in parameters_versions:
parameters = device_model.parameters[parameter_version]
for parameter in previous_parameters:
# TODO This fails for surprising amount of devices. Either we need to fix somethign deep in parameter creation, or we just cannot make it subsets
# TODO This fails for surprising amount of devices. Either we need to fix somethign deep in parameter creation, or we just cannot make it subsets. or it is plus vs basic?
if parameter not in parameters:
# print(f"WARNING: Parameter {parameter} from previous version not present in version {parameter_version} for device {device_model.name}")
pass
# print(f"WARNING: Parameter {parameter} from previous version not present in version {parameter_version} for device {device_model.name}")

previous_parameters = parameters

Expand All @@ -83,5 +85,6 @@

write_output(dict_devices_sensor, dict_devices_parameters)
write_known_devices(dict_devices_sensor, dict_devices_parameters)
write_dump(dict_devices_sensor, dict_devices_parameters)

print("SUCCESS")
15 changes: 10 additions & 5 deletions src/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,12 @@ def write_output(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], dict_de
shutil.rmtree(OUTPUT_DIR)
os.mkdir(OUTPUT_DIR)

sensors_all: list[SensorDump] = []
params_all: list[ParameterDump] = []
for device, sensors in dict_devices_sensor.items():
sensors_all.extend([dump_sensor(sensor, device) for sensor in sensors])
with open(os.path.join(OUTPUT_DIR, f'{device.device_name}.{device.version.first_version}.{device.version.last_version}.sensors.csv'), "w", encoding="utf-8") as text_file:
text_file.write(CSV_HEADER)
text_file.write(csv_from_sensors(sensors, device.device_name))

for device_param, parameters in dict_devices_parameter.items():
params_all.extend([dump_param(param, device_param) for param in parameters])
with open(os.path.join(OUTPUT_DIR, f'{device_param.device_name}.{device_param.version.first_version}.{device_param.version.last_version}.params.basic.csv'), "w", encoding="utf-8") as text_file:
text_file.write(CSV_HEADER)
text_file.write(csv_from_parameters(parameters, device_param.device_name, False))
Expand All @@ -187,11 +183,20 @@ def write_output(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], dict_de
text_file.write(csv_from_parameters(parameters, device_param.device_name, True))



def write_dump(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], dict_devices_parameter: dict[DeviceParameters, list[Parameter]]):
if os.path.exists(DUMP_DIR):
shutil.rmtree(DUMP_DIR)
os.mkdir(DUMP_DIR)

sensors_all: list[SensorDump] = []
params_all: list[ParameterDump] = []

for device, sensors in dict_devices_sensor.items():
sensors_all.extend([dump_sensor(sensor, device) for sensor in sensors])

for device_param, parameters in dict_devices_parameter.items():
params_all.extend([dump_param(param, device_param) for param in parameters])

# Write out JSON and CVS of all params and sensors for an further processing in different tools
jsonpickle.set_encoder_options('json', sort_keys=True, indent=4)
sensors_all.sort()
Expand Down
15 changes: 11 additions & 4 deletions src/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@


class DeviceParameters(DeviceVersion):
def __init__(self, device_name: str, version_range: VersionRange, params_basic: int, params_plus: int, controller_code: int):
def __init__(self, device_name: str, version_range: VersionRange, has_plus_variant: bool, params_basic: int, params_plus: int, controller_code: int):
super().__init__(device_name, version_range)
self.has_plus_variant = has_plus_variant
self.params_basic = params_basic
self.params_plus = params_plus
self.controller_code = controller_code
Expand Down Expand Up @@ -50,11 +51,17 @@ def get_device_parameters() -> dict[DeviceParameters, list[Parameter]]:
params_basic = params_plus = 60
else:
match = re.search(
r'public const int PARAMETER_COUNT_(BASIC|AUTO) = (?P<params_basic>\d*);[\s\S]*'
r'public const int PARAMETER_COUNT_(PLUS|MANUAL) = (?P<params_plus>\d*);', file_str)
r'public const int PARAMETER_COUNT_(?P<basic_auto>BASIC|AUTO) = (?P<params_basic>\d*);[\s\S]*'
r'public const int PARAMETER_COUNT_(?P<plus_manual>PLUS|MANUAL) = (?P<params_plus>\d*);', file_str)
assert match
params_basic = int(match.group('params_basic'))
params_plus = int(match.group('params_plus'))
has_plus_variant = match.group('plus_manual') == "PLUS"

# We assume that auto vs manual params are always the same number - prove it through this sanity check
if match.group('basic_auto') == "AUTO":
assert match.group('plus_manual') == "MANUAL"
assert params_basic == params_plus

match = re.search(
r'public (new )?const (uint|byte) CONTROLLER_CODE = (?P<controller_code>\d*);[\s\S]*'
Expand All @@ -67,7 +74,7 @@ def get_device_parameters() -> dict[DeviceParameters, list[Parameter]]:
controller_code = int(match.group('controller_code'))

version_range = VersionRange(view_no, first_version, last_version)
device = DeviceParameters(device_name, version_range, params_basic, params_plus, controller_code)
device = DeviceParameters(device_name, version_range, has_plus_variant, params_basic, params_plus, controller_code)

params_basic_int = int(params_basic)

Expand Down
3 changes: 0 additions & 3 deletions src/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def check_converter(sensor: Sensor, device_name: str):
elif "CurrentDipswitchValue" == sensor.name_current and (device_name + "Basic" in dipswitch_dict or device_name + "Plus" in dipswitch_dict):
sensor.converter = copy.deepcopy(converters_map['ConverterUInt16DipswitchValue'])
sensor.converter_match = "patched"
elif "CurrentSystemStatus" == sensor.name_current and (device_name == 'DecentralAir70') and sensor.converter == 'ConverterUInt16ToUNumber':
sensor.converter = copy.deepcopy(converters_map['ConverterUInt16DipswitchValue'])
sensor.converter_match = "patched"


def get_dict_devices_sensor(
Expand Down

0 comments on commit 7a3de5a

Please sign in to comment.