Skip to content

Commit

Permalink
Fix output format file
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed Jul 5, 2024
1 parent b87fd40 commit f613545
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/homematicip/cli/hmip.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,32 @@ def toggle_garage_door(id: str, channel: int = None):
f"Run toggle_garage_door for device {get_device_name(device)} with result: {result.status_text} ({result.status})")


@cli.command
@click.argument("count", type=int, nargs=1)
def test(count: int):
"""Test command."""
runner = asyncio.run(get_initialized_runner())

ids = [
'9d726201-be53-45cb-b32b-3ef61d3ec11c',
'1eae867f-0b2f-4c47-b7b8-987166ef33a3',
'a1dc1d91-55f2-42a1-925e-29850cd9c0dc',
'357814f6-c743-4917-a46e-b33a1ab81454',
'125a16cc-f666-473d-9e21-8dbac44d165a',
'd2655bdb-75cf-45b0-b1fa-9d45f88cc3c8',
'61805e71-eda6-4790-838b-db0aa0c241dd']

for i in range(count):
id = ids[i % len(ids)]
click.echo(f"#{i:00}: Run for device {get_group_name(runner.model.groups[id])}")
result = asyncio.run(async_set_point_temperature_group(runner.rest_connection, runner.model.groups[id], 12))
click.echo(f"Result: {result.status_text} ({result.status})")

#
# await async_set_point_temperature_group(runner.rest_connection, runner.model.groups["GROUP_1"], 22.0)
# runner.model.groups["GROUP_1"]


@run.command
@click.option("-id", type=str, required=False, help="ID of the device or group, which the run command is applied to.")
@click.option("-c", "--channel", type=int, required=False, default=None,
Expand Down
2 changes: 1 addition & 1 deletion src/homematicip/configuration/config_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_output_format_config(cls) -> OutputFormatConfig | None:
config_file_path = os.path.join(os.getcwd(), "data/output-format.json")

if not os.path.exists(config_file_path):
return None
return OutputFormatConfig()

return cls.output_format_from_file(config_file_path)

Expand Down
132 changes: 128 additions & 4 deletions src/homematicip/configuration/output_format_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,133 @@
from typing import List


def _default_functional_channel_attributes() -> List[str]:
return [
"accelerationSensorEventFilterPeriod",
"accelerationSensorMode",
"accelerationSensorNeutralPosition",
"accelerationSensorSensitivity",
"accelerationSensorTriggerAngle",
"accelerationSensorTriggered",
"actualTemperature",
"alarmContactType",
"authorized",
"averageIllumination",
"binaryBehaviorType",
"blindModeActive",
"colorTemperature",
"currentIllumination",
"currentPowerConsumption",
"dimLevel",
"display",
"doorHandleType",
"doorLockDirection",
"doorState",
"energyCounter",
"genericAlarmSignal",
"highestIllumination",
"humidity",
"illumination",
"impulseDuration",
"leftCounter",
"leftRightCounterDelta",
"lowBat",
"lowestIllumination",
"moistureDetected",
"motionBufferActive",
"motionDetected",
"motorState",
"multiModeInputMode",
"notificationSoundTypeHighToLow",
"notificationSoundTypeLowToHigh",
"on",
"passageBlindtime",
"passageDirection",
"passageSensorSensitivity",
"powerMainsFailure",
"previousShutterLevel",
"previousSlatsLevel",
"primaryShadingLevel",
"processing",
"profileMode",
"pumpFollowUpTime",
"pumpLeadTime",
"pumpProtectionDuration",
"pumpProtectionSwitchingInterval",
"raining",
"rightCounter",
"rssiDeviceValue",
"rssiPeerValue",
"saturationLevel",
"secondaryShadingLevel",
"selfCalibrationInProgress",
"setPointTemperature",
"shutterLevel",
"simpleRGBColorState",
"slatsLevel",
"smokeDetectorAlarmType",
"storm",
"sunshine",
"temperatureExternalDelta",
"temperatureExternalOne",
"temperatureExternalTwo",
"temperatureOffset",
"todayRainCounter",
"todaySunshineDuration",
"totalRainCounter",
"totalSunshineDuration",
"unreach",
"valveActualTemperature",
"valvePosition",
"valveState",
"vaporAmount",
"waterlevelDetected",
"windSpeed",
"windowState",
"yesterdayRainCounter",
"yesterdaySunshineDuration"
]


def _default_group_attributes() -> List[str]:
return [
"activeProfile",
"actualTemperature",
"boostDuration",
"boostMode",
"humidity",
"partyMode",
"valvePosition",
"windowState",
"motionDetected",
"presenceDetected",
"on",
"triggered",
"primaryShadingLevel",
"secondaryShadingLevel",
"shutterLevel",
"slatsLevel",
"moistureDetected",
"waterLevelDetected",
"signalAcoustic",
"signalOptical",
"illumination",
"enabled",
"ventilationLevel"
]


def _default_device_attributes() -> List[str]:
return [
"connectionType",
"modelType",
"permanentlyReachable",
"externalService"
]


@dataclass
class OutputFormatConfig:

functional_channel_attributes: List[str] = field(default_factory=list)
group_attributes: List[str] = field(default_factory=list)
device_attributes: List[str] = field(default_factory=list)
functional_channel_attributes: List[str] = field(default_factory=_default_functional_channel_attributes)
group_attributes: List[str] = field(default_factory=_default_group_attributes)
device_attributes: List[str] = field(default_factory=_default_device_attributes)
27 changes: 27 additions & 0 deletions tests/config/test_config_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from unittest.mock import patch, mock_open

from homematicip.configuration.config_io import ConfigIO


def test_get_output_format_config_without_existing_config_file():
with patch("os.path.exists", return_value=False):
output_format_config = ConfigIO.get_output_format_config()
assert output_format_config is not None


def test_get_output_format_config_with_existing_config_file():
format_file_content = r'''
{
"device_attributes": ["id", "label", "modelType"],
"group_attributes": ["id", "label"],
"functional_channel_attributes": ["id", "label", "functionalChannelType"]
}
'''
mock_data = mock_open(read_data=format_file_content)
with patch("os.path.exists", return_value=True):
with patch("builtins.open", mock_data):
output_format_config = ConfigIO.get_output_format_config()
assert output_format_config is not None
assert output_format_config.device_attributes == ["id", "label", "modelType"]
assert output_format_config.group_attributes == ["id", "label"]
assert output_format_config.functional_channel_attributes == ["id", "label", "functionalChannelType"]

0 comments on commit f613545

Please sign in to comment.