make all objects able to print their own values
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import dsmr_parser.obis_name_mapping
|
||||
import datetime
|
||||
|
||||
|
||||
class Telegram(object):
|
||||
@@ -48,7 +49,7 @@ class Telegram(object):
|
||||
def __str__(self):
|
||||
output = ""
|
||||
for attr, value in self:
|
||||
output += "{}: \t {} \t[{}]\n".format(attr, str(value.value), str(value.unit))
|
||||
output += "{}: \t {}\n".format(attr, str(value))
|
||||
return output
|
||||
|
||||
|
||||
@@ -87,6 +88,10 @@ class MBusObject(DSMRObject):
|
||||
else:
|
||||
return self.values[1]['unit']
|
||||
|
||||
def __str__(self):
|
||||
output = "{}\t[{}] at {}".format(str(self.value), str(self.unit), str(self.datetime.astimezone().isoformat()))
|
||||
return output
|
||||
|
||||
|
||||
class CosemObject(DSMRObject):
|
||||
|
||||
@@ -98,6 +103,13 @@ class CosemObject(DSMRObject):
|
||||
def unit(self):
|
||||
return self.values[0]['unit']
|
||||
|
||||
def __str__(self):
|
||||
print_value = self.value
|
||||
if isinstance(self.value, datetime.datetime):
|
||||
print_value = self.value.astimezone().isoformat()
|
||||
output = "{}\t[{}]".format(str(print_value), str(self.unit))
|
||||
return output
|
||||
|
||||
|
||||
class ProfileGeneric(DSMRObject):
|
||||
pass # TODO implement
|
||||
|
||||
Reference in New Issue
Block a user