Skip to content

Commit

Permalink
Group management
Browse files Browse the repository at this point in the history
  • Loading branch information
mika1337 committed May 14, 2021
1 parent cedc329 commit 6202227
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
20 changes: 20 additions & 0 deletions chronosoft8puppeteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def __init__(self):
logger.error('Failed to load config file {}'.format(shutters_config_file))
raise

# Load groups config
groups_config_file = os.path.join( config_path
, 'groups.json')
try:
groups_config = json.load(open(groups_config_file))
self._groups = groups_config['groups']
except:
logger.error('Failed to load config file {}'.format(groups_config_file))
raise

# Debug
self._debug = False
if 'debug' in self._config:
Expand Down Expand Up @@ -83,9 +93,19 @@ def __init__(self):
def get_shutters(self):
return self._shutters

def get_groups(self):
return self._groups

def drive_shutter(self,shutter,command):
self._cmd_queue.put( (shutter,command) )

def drive_group(self,group,command):
for group_data in self._groups:
if group_data['name'] == group:
for shutter in group_data['shutters']:
self._cmd_queue.put( (shutter,command) )
break

def get_programs(self):
return self._plugins['scheduling'].get_programs()

Expand Down
2 changes: 1 addition & 1 deletion config/chronosoft8-puppeteer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"active_low" : true
}
}
}
}
29 changes: 29 additions & 0 deletions config/groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"groups":
[
{
"name": "Général",
"shutters": [ "Cuisine","Salon 2","Salon 1","Entrée 2","Entrée 1","Chambre" ]
},
{
"name": "Entrée",
"shutters": [ "Entrée 2", "Entrée 1" ]
},
{
"name": "Salon",
"shutters": [ "Salon 2", "Salon 1" ]
},
{
"name": "Cuisine",
"shutters": [ "Cuisine" ]
},
{
"name": "Chambre",
"shutters": [ "Chambre" ]
},
{
"name": "Maison",
"shutters": [ "Cuisine","Salon 2","Salon 1","Entrée 2","Entrée 1" ]
}
]
}
14 changes: 13 additions & 1 deletion plugins/websocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def process_input(json_input,endpoint):
if command == 'get_shutters':
shutters = cs8p.get_shutters()
output = { 'status': 'ok', 'shutters': shutters }
elif command == 'get_groups':
groups = cs8p.get_groups()
output = { 'status': 'ok', 'groups': groups }
elif command == 'get_programs':
programs = cs8p.get_programs()
output = { 'status': 'ok', 'programs': programs }
Expand All @@ -121,7 +124,7 @@ def process_input(json_input,endpoint):
output = { 'status': 'error' }
else:
output = { 'status': 'ok' }
elif command == 'drive':
elif command == 'drive_shutter':
try:
command = data['args']['command']
shutter = data['args']['shutter']
Expand All @@ -130,5 +133,14 @@ def process_input(json_input,endpoint):
else:
cs8p.drive_shutter(shutter,command)
output = { 'status': 'ok' }
elif command == 'drive_group':
try:
command = data['args']['command']
group = data['args']['group']
except:
output = { 'status': 'error' }
else:
cs8p.drive_group(group,command)
output = { 'status': 'ok' }
return output

0 comments on commit 6202227

Please sign in to comment.