diff --git a/pyHS100/pyHS100.py b/pyHS100/pyHS100.py index 4143b076..8d388c2a 100644 --- a/pyHS100/pyHS100.py +++ b/pyHS100/pyHS100.py @@ -9,6 +9,7 @@ import codecs import json import datetime import sys +import re _LOGGER = logging.getLogger(__name__) @@ -104,7 +105,7 @@ class SmartPlug(object): False if command is not successful or the switch doesn't support energy metering Dict with the current readings """ - if self.model == 100: + if self.model != 110: return False response = self._send_command('{"emeter":{"get_realtime":{}}}') @@ -126,7 +127,7 @@ class SmartPlug(object): False if command is not successful or the switch doesn't support energy metering Dict where the keys represent the days, and the values are the aggregated statistics """ - if self.model == 100: + if self.model != 110: return False response = self._send_command('{"emeter":{"get_daystat":{"month":' + str(month) + ',"year":' + str(year) + '}}}') @@ -152,7 +153,7 @@ class SmartPlug(object): False if command is not successful or the switch doesn't support energy metering Dict - the keys represent the months, the values are the aggregated statistics """ - if self.model == 100: + if self.model != 110: return False response = self._send_command('{"emeter":{"get_monthstat":{"year":' + str(year) + '}}}') @@ -175,7 +176,7 @@ class SmartPlug(object): True: Success False: Failure or not supported by switch """ - if self.model == 100: + if self.model != 110: return False response = self._send_command('{"emeter":{"erase_emeter_stat":null}}') @@ -187,7 +188,7 @@ class SmartPlug(object): def current_consumption(self): """Get the current power consumption in Watt.""" - if self.model == 100: + if self.model != 110: return False response = self.get_emeter_realtime() @@ -252,10 +253,5 @@ class SmartPlug(object): def _identify_model(self): """Query sysinfo and determine model""" sys_info = self.get_info() - - if sys_info["system"]["get_sysinfo"]["model"][:5] == 'HS100': - model = 100 - elif sys_info["system"]["get_sysinfo"]["model"][:5] == 'HS110': - model = 110 - + model = re.sub('HS', '', sys_info["system"]["get_sysinfo"]["model"][:5]) return model