def test_boolean(self): if _debug: TestBoolean._debug("test_boolean") obj = Boolean() assert obj.value == False with self.assertRaises(TypeError): Boolean("some string") with self.assertRaises(TypeError): Boolean(1.0)
def test_boolean_bool(self): if _debug: TestBoolean._debug("test_boolean_bool") obj = Boolean(False) assert obj.value == False assert str(obj) == "Boolean(False)" obj = Boolean(True) assert obj.value == True assert str(obj) == "Boolean(True)"
def run(self): while not self.flag_stop: time.sleep(10) for obj in self.objs: objname = str(obj._values["objectName"]) for meter in self.meters: if meter.name == objname: obj._values["outOfService"] = Boolean( not meter.is_connected) obj._values["presentValue"] = Real( meter.getPresentValue()) fname = objname #output_csv = os.path.join ( str ( '/home/cleangat/bacdevice/csv' ), fname + u".csv" ) output_csv = os.path.join(str('/var/www/html'), fname + u".csv") mode = 'a' if sys.version_info.major < 3: mode += 'b' with open(output_csv, mode) as f: writer = csv.writer(f, delimiter=',') outputvar = meter.getPresentValue() writer.writerow([ datetime.datetime.now().replace( microsecond=0).isoformat(" "), outputvar ]) f.close()
def test_primitive_tag(self): if _debug: TestNameValue._debug("test_primitive_tag") # try the primitive types name_value_endec("status", Boolean(False)) name_value_endec("age", Integer(3)) name_value_endec("experience", Real(73.5))
def boolean_decode(tag): """Decode an boolean application tag into an boolean.""" if _debug: boolean_decode._debug("boolean_decode %r", tag) obj = Boolean(tag) if _debug: boolean_decode._debug(" - obj: %r", obj) return obj
def test_boolean_tag(self): if _debug: TestBoolean._debug("test_boolean_tag") tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 1, xtob('01')) obj = Boolean(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.integerAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Boolean(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Boolean(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Boolean(tag)
def create_AI(oid=1, pv=0, name="AI", units=None): aio = AnalogInputObject( objectIdentifier=("analogInput", oid), objectName=name, presentValue=pv, units=units, outOfService=Boolean(False), ) aio = _make_mutable(aio, identifier="outOfService", mutable=True) return aio
def run(self): while not self.flag_stop: time.sleep(1) for obj in self.objs: objname = str(obj._values['objectName']) for meter in self.meters: if meter.name == objname: obj._values['outOfService'] = Boolean( not meter.is_connected) obj._values['presentValue'] = Real(meter.dust_small * 100)
def run(self): while not self.flag_stop: time.sleep(1) for obj in self.objs: objname = str(obj._values["objectName"]) for meter in self.meters: if meter.name == objname: obj._values["outOfService"] = Boolean( not meter.is_connected) obj._values["presentValue"] = Real( meter.getPresentValue())
def boolean_endec(v, x): """Pass the value to Boolean, construct a tag from the hex string, and compare results of encode and decoding each other.""" if _debug: boolean_endec._debug("boolean_endec %r %r", v, x) tag = boolean_tag(x) if _debug: boolean_endec._debug(" - tag: %r, %r", tag, tag.tagData) obj = Boolean(v) if _debug: boolean_endec._debug(" - obj: %r, %r", obj, obj.value) assert boolean_encode(obj) == tag assert boolean_decode(tag) == obj
def test_boolean_application_to_object(self): if _debug: TestApplicationTag._debug("test_boolean_application_to_object") # null obj_endec(Null(), '00') # boolean obj_endec(Boolean(True), '11') obj_endec(Boolean(False), '10') # unsigned obj_endec(Unsigned(0), '2100') obj_endec(Unsigned(1), '2101') obj_endec(Unsigned(127), '217F') obj_endec(Unsigned(128), '2180') # integer obj_endec(Integer(0), '3100') obj_endec(Integer(1), '3101') obj_endec(Integer(-1), '31FF') obj_endec(Integer(128), '320080') obj_endec(Integer(-128), '3180') # real obj_endec(Real(0), '4400000000') obj_endec(Real(1), '443F800000') obj_endec(Real(-1), '44BF800000') obj_endec(Real(73.5), '4442930000') # double obj_endec(Double(0), '55080000000000000000') obj_endec(Double(1), '55083FF0000000000000') obj_endec(Double(-1), '5508BFF0000000000000') obj_endec(Double(73.5), '55084052600000000000') # octet string obj_endec(OctetString(xtob('')), '60') obj_endec(OctetString(xtob('01')), '6101') obj_endec(OctetString(xtob('0102')), '620102') obj_endec(OctetString(xtob('010203040506')), '6506010203040506') # character string obj_endec(CharacterString(''), '7100') obj_endec(CharacterString('a'), '720061') obj_endec(CharacterString('abcde'), '7506006162636465') # bit string obj_endec(BitString([]), '8100') obj_endec(BitString([0]), '820700') obj_endec(BitString([1]), '820780') obj_endec(BitString([1, 1, 1, 1, 1]), '8203F8') obj_endec(BitString([1] * 10), '8306FFC0') # enumerated obj_endec(Enumerated(0), '9100') obj_endec(Enumerated(1), '9101') obj_endec(Enumerated(127), '917F') obj_endec(Enumerated(128), '9180') # date obj_endec(Date((1, 2, 3, 4)), 'A401020304') obj_endec(Date((255, 2, 3, 4)), 'A4FF020304') obj_endec(Date((1, 255, 3, 4)), 'A401FF0304') obj_endec(Date((1, 2, 255, 4)), 'A40102FF04') obj_endec(Date((1, 2, 3, 255)), 'A4010203FF') # time obj_endec(Time((1, 2, 3, 4)), 'B401020304') obj_endec(Time((255, 2, 3, 4)), 'B4FF020304') obj_endec(Time((1, 255, 3, 4)), 'B401FF0304') obj_endec(Time((1, 2, 255, 4)), 'B40102FF04') obj_endec(Time((1, 2, 3, 255)), 'B4010203FF') # object identifier obj_endec(ObjectIdentifier(0, 0), 'C400000000') obj_endec(ObjectIdentifier(1, 0), 'C400400000') obj_endec(ObjectIdentifier(0, 2), 'C400000002') obj_endec(ObjectIdentifier(3, 4), 'C400C00004')
def test_boolean_copy(self): if _debug: TestBoolean._debug("test_boolean_copy") obj1 = Boolean(True) obj2 = Boolean(obj1) assert obj2.value == True
def test_boolean_statement(self): if _debug: TestExtendedTagStatements._debug("test_boolean_statement") assert statement_to_tag("boolean false") == tag_encode(Boolean(False)) assert statement_to_tag("boolean true") == tag_encode(Boolean(True)) assert statement_to_tag("boolean true context 2") == tag_encode(Boolean(True), context=2)
def boolean_statement(value): if _debug: boolean_statement._debug("boolean_statement %r", value) return Boolean(value)