Skip to content
Open
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
4 changes: 2 additions & 2 deletions xsense/entity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from xsense.entity_map import entities
from xsense.mapping import map_values
from xsense.mapping import map_bool, map_values


class Entity:
Expand All @@ -21,7 +21,7 @@ def __init__(
def set_data(self, values: dict):
data = values.copy()
if 'online' in values:
self.online = values.pop('online') != '0'
self.online = map_bool(values.pop('online'))
if values.get('onlineTime'):
self.online = True
data |= data.pop('status', {})
Expand Down
222 changes: 199 additions & 23 deletions xsense/entity_map.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
from enum import Enum
from typing import Callable, Dict
from typing import Callable, Dict, Optional, Union


class EntityType(Enum):
ALARM = 'alarm'
BASE = "base"
BASESTATION = 'station'
CAMERA = 'camera'
CO = "co"
COMBI = 'combi'
DOOR = 'door'
HEAT = 'heat'
KEYPAD = 'keypad'
LIGHT = 'light'
LISTENER = 'listener'
MAILBOX = 'mailbox'
MOTION = 'motion'
RADON = 'radon'
REMOTE = 'remote'
SMARTDROP = 'smartdrop'
SMOKE = "smoke"
TEMPERATURE = "temperature"
WATER = "water"


def MuteAction(shadow: str = 'appMute', topic: str|None|Callable = '2nd_appmute', extra: Dict|None=None):
def MuteAction(
shadow: str = 'appMute',
topic: Union[str, Callable, None] = '2nd_appmute',
extra: Optional[Dict]=None,
mute_type: Optional[str]=None
):
data = {
'action': 'mute',
'topic': topic,
'shadow': shadow,
}
if extra:
data['extra'] = extra
if mute_type is not None:
data.setdefault('extra', {})['muteType'] = mute_type

return data

Expand All @@ -42,7 +55,8 @@ def FireDrillAction():
return {
'action': 'firedrill',
'topic': '2nd_firedrill',
'shadow': 'appFireDrill'
'shadow': 'appFireDrill',
'data': {'drill': '1'}
}


Expand All @@ -56,17 +70,40 @@ def SATestAction(shadow = 'appSelfTest'):


entities = {
'SAL51': {}, # listener
'SAL100': {}, # listener
'SAL51': {
'type': EntityType.LISTENER,
'actions': [
MuteAction('appListener', mute_type='1'),
],
},
'SAL100': {
'type': EntityType.LISTENER,
'actions': [
MuteAction('appListener', mute_type='1'),
],
},
'SBS10': {
'type': EntityType.BASESTATION,
},
'SBS50': {
'type': EntityType.BASESTATION,
'identifier': lambda entity: f'SBS50{entity.sn}',
},
# SSC0A - Camera
# SSC0B
'SSC0A': {
'type': EntityType.CAMERA,
},
'SSC0B': {
'type': EntityType.CAMERA,
},
'SC01-MN': {
'type': EntityType.COMBI,
},
'SC01-MR': {
'type': EntityType.COMBI,
'actions': [
MuteAction('appSc07mrMute', mute_type='1'),
],
},
'SC06-WX': {
'identifier': lambda entity: f'SC06-WX-{entity.sn}',
'type': EntityType.COMBI,
Expand All @@ -78,21 +115,60 @@ def SATestAction(shadow = 'appSelfTest'):
'identifier': lambda entity: f'SC07-MR-{entity.sn}',
'type': EntityType.COMBI,
'actions': [
MuteAction('appSc07mrMute', mute_type='1'),
]
},
'SC07-WX': {
'identifier': lambda entity: f'SC07-WX-{entity.sn}',
'type': EntityType.COMBI,
'actions': [
MuteAction('1')
MuteAction(mute_type='1')
]
},
# 'SDA51': {}, - Driveway alarm
'SD11-MR': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'SD19-MN': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'SD19-MR': {
'type': EntityType.SMOKE,
},
'SDA51': {
'type': EntityType.ALARM,
'actions': [
{
'action': 'mute',
'topic': '2nd_appdriveway',
'shadow': 'appDriveway',
'data': {'mute': '1'}
},
],
},
'SDS0A': {
'type': EntityType.DOOR,
},
# 'SES01': {}, - Door sensor
# 'SKF01': {}, - Remote Control
'SES01': {
'type': EntityType.DOOR,
},
'SKF01': {
'type': EntityType.REMOTE,
},
'SK0Z-3S': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'SKP01': {
'type': EntityType.KEYPAD,
},
'SKP0A': {
'type': EntityType.KEYPAD,
},
Expand All @@ -110,69 +186,112 @@ def SATestAction(shadow = 'appSelfTest'):
'SMS0A': {
'type': EntityType.MOTION,
},
# 'SSD01': {},
# 'SPL51': {},
# 'SSL51': {},
'SMS01': {
'type': EntityType.MOTION,
},
'SPL51': {
'type': EntityType.LIGHT,
},
'SSD01': {
'type': EntityType.SMARTDROP,
},
'SSL51': {
'type': EntityType.LIGHT,
},
'STH0A': {
'type': EntityType.TEMPERATURE,
'actions': [
TestAction('thSelfTest'),
MuteAction('1', 'extendMute')
MuteAction('extendMute', '2nd_appmute', extra={'type': 'STH0A'}, mute_type='1')
],
},
'STH0B': {
'type': EntityType.TEMPERATURE,
'actions': [
TestAction('thSelfTest'),
MuteAction('1', 'extendMute')
MuteAction('extendMute', '2nd_appmute', extra={'type': 'STH0B'}, mute_type='1')
],
},
'STH0C': {
'type': EntityType.TEMPERATURE,
},
'STH51': {
'type': EntityType.TEMPERATURE,
'actions': [
TestAction('thSelfTest'),
MuteAction('1', 'extendMute')
MuteAction('extendMute', '2nd_appmute', extra={'type': 'STH51'}, mute_type='1')
],
},
# 'SWL51': {},
'SWL51': {
'type': EntityType.LIGHT,
},
'SWS0A': {
'type': EntityType.WATER,
},
'SWS0B': {
'type': EntityType.WATER,
},
'SWS51': {
'type': EntityType.WATER,
'actions': [
TestAction('waterSelfTest'),
MuteAction(shadow='appWater', topic='2nd_appwater', extra={'silencetime': '', 'setType': '0'})
MuteAction(shadow='appWater', topic='2nd_appwater', extra={'silenceTime': '', 'setType': '0'})
],
},
'CB0Z-3S': {
'type': EntityType.COMBI,
},
'LP/N-SA-0B': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'LP/N-SCA-0A': {
'type': EntityType.COMBI,
},
'XC0C-iA': {
'type': EntityType.CO,
},
'XC0C-iR': {
'type': EntityType.CO,
},
'XC0M-iR': {
'type': EntityType.CO,
},
'XC01-M': {
# CO RF
'type': EntityType.CO,
'actions': [
TestAction(shadow='appCoSelfTest'),
MuteAction('1', '"appCoMute')
MuteAction('appCoMute', mute_type='1')
]
},
'XC04-WX': {
'identifier': lambda entity: f'XC04-WX-{entity.sn}',
'type': EntityType.CO,
'actions': [
MuteAction('1')
MuteAction(mute_type='1')
]
},
'XH02-M': {
'type': EntityType.HEAT,
'actions': [
TestAction(shadow='appXh02mSelfTest'),
MuteAction('appXh02mMute', mute_type='1', extra={'userParam': 'source=1'}),
]
},
'XP0A-MR': {
'type': EntityType.COMBI,
'actions': [
TestAction(shadow='app2ndSelfTest'),
MuteAction('appXp0amrMute', mute_type='1', extra={'userParam': 'source=1'}),
FireDrillAction()
]
},
'XR0A-iR': {
'type': EntityType.RADON,
},
'XP02S-MR': {
'type': EntityType.SMOKE,
'actions': [
Expand All @@ -196,13 +315,70 @@ def SATestAction(shadow = 'appSelfTest'):
'type': EntityType.SMOKE,
'actions': [
TestAction(),
MuteAction(),
MuteAction('app2ndMute', mute_type='1'),
FireDrillAction(),
],
},
'XS03-iWX': {
# Smoke RF
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'XS03-WX': {
'type': EntityType.SMOKE,
},
'XS0D-MR': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
],
},
'XS0D-MR61': {
'type': EntityType.SMOKE,
},
'XC0C-MR': {
'type': EntityType.CO,
},
'XP0A-iR': {
'type': EntityType.COMBI,
},
'XPOA-IR': {
'type': EntityType.COMBI,
},
'XP0H-MR': {
'type': EntityType.COMBI,
'actions': [
MuteAction('appSc07mrMute', mute_type='1'),
],
},
'XP0H-iR': {
'type': EntityType.COMBI,
},
'XP0J-iA': {
'type': EntityType.COMBI,
},
'XP0P-MR': {
'type': EntityType.COMBI,
'actions': [
MuteAction('appSc07mrMute', mute_type='1'),
],
},
'XS0B-iR': {
'type': EntityType.SMOKE,
},
'XS0E-iR': {
'type': EntityType.SMOKE,
},
'XS0F-PMA': {
'type': EntityType.SMOKE,
'actions': [
TestAction(),
MuteAction('app2ndMute', mute_type='1'),
],
},
'XS0R-iA': {
'type': EntityType.SMOKE,
},
'XS03-WX': {}
}
Loading