Skip to content

Commit

Permalink
Added all functional channel actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed May 6, 2024
1 parent 37965a0 commit 68fe8f3
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 8 deletions.
153 changes: 151 additions & 2 deletions src/homematicip/action/functional_channel_actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from homematicip.action.action import Action
from homematicip.model.enums import AccelerationSensorMode, AccelerationSensorNeutralPosition, \
AccelerationSensorSensitivity, NotificationSoundType
AccelerationSensorSensitivity, NotificationSoundType, DoorCommand, LockState, RGBColorState, ClimateControlDisplay, \
AcousticAlarmSignal, AcousticAlarmTiming, WaterAlarmTrigger
from homematicip.model.functional_channels import FunctionalChannel
from homematicip.runner import Runner

Expand Down Expand Up @@ -40,7 +41,7 @@ async def action_start_impulse(runner: Runner, fc: FunctionalChannel):
return await runner.rest_connection.async_post("device/control/startImpulse", data)


@Action.allowed_types("DIMMER_CHANNEL")
@Action.allowed_types("DIMMER_CHANNEL", "MULTI_MODE_INPUT_DIMMER_CHANNEL", "NOTIFICATION_LIGHT_CHANNEL")
async def action_set_dim_level(runner: Runner, fc: FunctionalChannel, dim_level: float):
data = {"channelIndex": fc.index, "deviceId": fc.deviceId, "dimLevel": dim_level}
return await runner.rest_connection.async_post("device/control/setDimLevel", data)
Expand Down Expand Up @@ -128,3 +129,151 @@ async def set_operation_lock(runner: Runner, fc: FunctionalChannel, operation_lo
"operationLock": operation_lock
}
return await runner.rest_connection.async_post("device/configuration/setOperationLock", data)


@Action.allowed_types("DOOR_CHANNEL")
async def action_send_door_command(runner: Runner, fc: FunctionalChannel, door_command: DoorCommand):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"doorCommand": str(door_command),
}
return await runner.rest_connection.async_post("device/control/sendDoorCommand", data)


@Action.allowed_types("DOOR_LOCK_CHANNEL")
async def action_set_door_state(runner: Runner, fc: FunctionalChannel, lock_state: LockState, pin: str = None):
data = {
"deviceId": fc.deviceId,
"channelIndex": fc.index,
"authorizationPin": pin,
"targetLockState": str(lock_state),
}
return await runner.rest_connection.async_post("device/control/setLockState", data)


@Action.allowed_types("NOTIFICATION_LIGHT_CHANNEL")
async def action_set_rgb_dim_level(runner: Runner, fc: FunctionalChannel, rgb: RGBColorState, dim_level: float):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"simpleRGBColorState": str(rgb),
"dimLevel": dim_level,
}
return await runner.rest_connection.async_post("device/control/setSimpleRGBColorDimLevel", data)


@Action.allowed_types("NOTIFICATION_LIGHT_CHANNEL")
async def action_set_rgb_dim_level_with_time(
runner: Runner,
fc: FunctionalChannel,
rgb: RGBColorState,
dim_level: float,
on_time: float,
ramp_time: float,
):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"simpleRGBColorState": str(rgb),
"dimLevel": dim_level,
"onTime": on_time,
"rampTime": ramp_time,
}
return await runner.rest_connection.async_post("device/control/setSimpleRGBColorDimLevelWithTime", data)


@Action.allowed_types("SHADING_CHANNEL")
async def action_set_primary_shading_level(runner: Runner, fc: FunctionalChannel, primary_shading_level: float):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"primaryShadingLevel": primary_shading_level,
}
return await runner.rest_connection.async_post("device/control/setPrimaryShadingLevel", data)


@Action.allowed_types("SHADING_CHANNEL")
async def action_set_secondary_shading_level(runner: Runner, fc: FunctionalChannel, primary_shading_level: float,
secondary_shading_level: float):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"primaryShadingLevel": primary_shading_level,
"secondaryShadingLevel": secondary_shading_level,
}
return await runner.rest_connection.async_post("device/control/setSecondaryShadingLevel", data)


@Action.allowed_types("SWITCH_MEASURING_CHANNEL")
async def action_reset_energy_counter(runner: Runner, fc: FunctionalChannel):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId
}
return await runner.rest_connection.async_post("device/control/resetEnergyCounter", data)


@Action.allowed_types("WALL_MOUNTED_THERMOSTAT_PRO_CHANNEL")
async def action_set_display(runner: Runner, fc: FunctionalChannel, display: ClimateControlDisplay):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"display": str(display),
}
return await runner.rest_connection.async_post("device/configuration/setClimateControlDisplay", data)


@Action.allowed_types("WATER_SENSOR_CHANNEL")
async def action_set_acoustic_alarm_signal(runner: Runner, fc: FunctionalChannel,
acoustic_alarm_signal: AcousticAlarmSignal):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"acousticAlarmSignal": str(acoustic_alarm_signal),
}
return await runner.rest_connection.async_post("device/configuration/setAcousticAlarmSignal", data)


@Action.allowed_types("WATER_SENSOR_CHANNEL")
async def action_set_acoustic_alarm_timing(runner: Runner, fc: FunctionalChannel,
acoustic_alarm_timing: AcousticAlarmTiming):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"acousticAlarmTiming": str(acoustic_alarm_timing),
}
return await runner.rest_connection.async_post("device/configuration/setAcousticAlarmTiming", data)


@Action.allowed_types("WATER_SENSOR_CHANNEL")
async def action_set_acoustic_water_alarm_trigger(runner: Runner, fc: FunctionalChannel,
acoustic_water_alarm_trigger: WaterAlarmTrigger):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"acousticWaterAlarmTrigger": str(acoustic_water_alarm_trigger),
}
return await runner.rest_connection.async_post("device/configuration/setAcousticWaterAlarmTrigger", data)


@Action.allowed_types("WATER_SENSOR_CHANNEL")
async def action_set_inapp_water_alarm_trigger(runner: Runner, fc: FunctionalChannel,
inapp_water_alarm_trigger: WaterAlarmTrigger):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"inAppWaterAlarmTrigger": str(inapp_water_alarm_trigger),
}
return await runner.rest_connection.async_post("device/configuration/setInAppWaterAlarmTrigger", data)


@Action.allowed_types("WATER_SENSOR_CHANNEL")
async def action_set_siren_water_alarm_trigger(runner: Runner, fc: FunctionalChannel,
siren_water_alarm_trigger: WaterAlarmTrigger):
data = {
"channelIndex": fc.index,
"deviceId": fc.deviceId,
"sirenWaterAlarmTrigger": str(siren_water_alarm_trigger),
}
return await runner.rest_connection.async_post("device/configuration/setSirenWaterAlarmTrigger", data)
2 changes: 1 addition & 1 deletion src/homematicip/events/hmip_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, event_manager: EventManager, model: Model):
self._model = model
self._event_manager = event_manager

async def process_event(self, event_json):
async def process_event_async(self, event_json):
for event in event_json["events"].values():

LOGGER.info(f"Processing event {event['pushEventType']}")
Expand Down
2 changes: 1 addition & 1 deletion src/homematicip/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def _async_start_listening_for_updates(self, context: ConnectionContext):
hmip_event_handler = HmipEventHandler(event_manager=self.event_manager, model=self.model)
async for message in handler.listen(context, False):
try:
await hmip_event_handler.process_event(json.loads(message))
await hmip_event_handler.process_event_async(json.loads(message))

except Exception as e:
LOGGER.error(f"Error while handling incoming event. Message: {message}", exc_info=e)
Expand Down
Loading

0 comments on commit 68fe8f3

Please sign in to comment.