Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Commit

Permalink
update coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
treussart committed Mar 11, 2017
1 parent 3ccb7c5 commit 3797539
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Domoticz.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""For controlling Domoticz."""
import urllib
import ConfigParser
import os
Expand All @@ -8,8 +9,10 @@


class Domoticz:
"""Class for controlling Domoticz."""

def __init__(self):
"""Recover the config files for accessing to Domoticz instance."""
config_name = "conf.cfg"
config_file = os.path.join(os.path.dirname(__file__), config_name)
self.config = ConfigParser.ConfigParser()
Expand All @@ -19,6 +22,7 @@ def __init__(self):
self.url = "http://" + self.host + ":" + self.port

def convert_name_to_idx(self, what, where):
"""Convert the 'what' and the 'where', for recover the idx of the device in Domoticz."""
if where is None:
for (key, val) in self.config.items("devices"):
if what.lower().strip() == key.lower().strip():
Expand All @@ -30,6 +34,7 @@ def convert_name_to_idx(self, what, where):
return 0

def switch(self, state, idx):
"""Switch the device in Domoticz."""
try:
f = urllib.urlopen(self.url + "/json.htm?type=command&param=switchlight&idx=" + str(idx) + "&switchcmd=" + str(state).title())
response = f.read()
Expand All @@ -39,6 +44,7 @@ def switch(self, state, idx):
LOGGER.error(str(e) + ' : ' + str(e.read()))

def get(self, idx):
"""Get the device's data in Domoticz."""
try:
f = urllib.urlopen(self.url + "/json.htm?type=devices&rid=" + str(idx))
response = f.read()
Expand Down

0 comments on commit 3797539

Please sign in to comment.