Skip to content

Commit

Permalink
Merge pull request #23 from fdegier/feature/add-force-support
Browse files Browse the repository at this point in the history
Feature/add force support
  • Loading branch information
fdegier authored Oct 19, 2024
2 parents 7a23aa1 + c4dfca2 commit e388abc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions jablotronpy/jablotronpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ def get_service_history(self, service_id: int, date_from: str = "", date_to: str
raise UnexpectedResponse("Unable to retrieve event history.")

def control_component(self, service_id: int, component_id: str, state: str, control_pg: bool = False,
service_type: str = "JA100"):
service_type: str = "JA100", force: bool = False):
"""
:param service_id: ID of your service, this ID can be obtained from get_services()
:param service_type: Type of your service, type can be obtained from output of get_services()
:param component_id:
:param control_pg:
:param state: For a section use either ARM or DISARM, for a PG use ON or OFF
:param force: Overwrite a blockage of the component
:return:
"""
if control_pg is True:
Expand All @@ -351,7 +352,8 @@ def control_component(self, service_id: int, component_id: str, state: str, cont
"authorization": {"authorization-code": f"{self.pin_code}"},
"control-components": [{
"actions": dict(action=control_type, value=state.upper()),
"component-id": component_id
"component-id": component_id,
"force": force
}]
}

Expand All @@ -365,7 +367,7 @@ def control_component(self, service_id: int, component_id: str, state: str, cont
if component["component-id"] == component_id and component["state"] == state.upper():
return component

raise UnexpectedResponse("Unable to control component")
raise UnexpectedResponse(f"Unable to control component, response: {data}")

def control_programmable_gate(self, service_id: int, component_id: str, on: bool):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_jablotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_get_programmable_gates(self):

def test_control_programmable_gate(self):
service_id = self.jablotron.get_services()[1]["service-id"]
pg_id = self.jablotron.get_programmable_gates(service_id=service_id)["states"][15]["cloud-component-id"]
pg_id = self.jablotron.get_programmable_gates(service_id=service_id)["states"][1]["cloud-component-id"]
data = self.jablotron.control_programmable_gate(service_id=service_id, component_id=pg_id, on=False)
assert data["component-id"] == pg_id
assert data["state"] == "OFF"

0 comments on commit e388abc

Please sign in to comment.