Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] lares 4 proof of concept #4

Draft
wants to merge 5 commits into
base: development/4support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ksenia_lares/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .base_api import BaseApi
from .ip_api import IpAPI
from .lares4_api import Lares4API

def get_api(config: dict) -> BaseApi:
"""
Expand All @@ -15,7 +16,8 @@ def get_api(config: dict) -> BaseApi:
if version == "IP":
return IpAPI(config)

if version == "IP":
raise ValueError("Lares 4.0 API not yet supported")
if version == "4":
raise
#return Lares4API(config)

raise ValueError(f"Unsupported API version: {version}")
3 changes: 1 addition & 2 deletions src/ksenia_lares/base_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from abc import ABC, abstractmethod
from typing import List, Optional
from ksenia_lares.types import AlarmInfo, Partition, Scenario, Zone, ZoneBypass

from ksenia_lares.types_ip import AlarmInfo, Partition, Scenario, Zone, ZoneBypass

class BaseApi(ABC):
"""Base API for the Ksenia Lares"""
Expand Down
15 changes: 9 additions & 6 deletions src/ksenia_lares/ip_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import aiohttp
from lxml import etree

from .types import (
from .types_ip import (
AlarmInfo,
Command,
Partition,
PartitionStatus,
Scenario,
Zone,
Zone as ZoneIP,
ZoneBypass,
ZoneStatus,
)
from .types_lares4 import (
Zone as ZoneLares4
)
from .base_api import BaseApi

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -70,7 +73,7 @@ async def info(self) -> AlarmInfo:

return info

async def get_zones(self) -> List[Zone]:
async def get_zones(self) -> List[ZoneIP]:
"""
Get status of all zones.

Expand All @@ -85,7 +88,7 @@ async def get_zones(self) -> List[Zone]:
)

return [
Zone(
ZoneIP(
id=index,
description=descriptions[index],
status=ZoneStatus(zone.find("status").text),
Expand Down Expand Up @@ -171,7 +174,7 @@ async def activate_scenario(
params = {"macroId": current.id}
return await self._send_command(Command.SET_MACRO, pin, params)

async def bypass_zone(self, zone: int | Zone, pin: str, bypass: ZoneBypass) -> bool:
async def bypass_zone(self, zone: int | ZoneIP | ZoneLares4, pin: str, bypass: ZoneBypass) -> bool:
"""
Activates or deactivates the bypass on the given zone.

Expand All @@ -184,7 +187,7 @@ async def bypass_zone(self, zone: int | Zone, pin: str, bypass: ZoneBypass) -> b
bool: True if the (un)bypass was executed successfully.
"""

if isinstance(zone, Zone):
if isinstance(zone, ZoneIP):
zone_id = zone.id
elif isinstance(zone, int):
zone_id = zone
Expand Down
Loading