def command_incoming(self, link, cmd): """ Callback for incoming commands received from bluetooth link. Change in States will be received in this callback :param link Link: :class:`link` object :param bytearray cmd: data received :rtype: None """ log.info("Len: " + str(len(cmd))) #log.debug("\n App: Cmd :", cmd) b_string = codecs.encode(cmd, 'hex') log.debug("*** Hex:* " + str(b_string) + " + Type: " + str(type(b_string))) #print("*** Hex:* " + str(b_string) + " + Type: " + str(type(b_string))) hmkit_inst = hmkit.get_instance() hmkit_inst.autoapi_dump.message_dump(cmd) cmd_obj = CommandResolver.resolve(cmd) log.debug("cmd_obj: " + str(cmd_obj)) #log.debug(" isinstance of LockState: " + str(isinstance(cmd_obj, lockstate.LockState))) if isinstance(cmd_obj, capabilities.Capabilities): #print("App: Capabilities received ") # Example: Capability Checks doorlock_capability = cmd_obj.get_capability( Identifiers.DOOR_LOCKS) is_sup = doorlock_capability.is_supported( msg_type.MsgType(Identifiers.DOOR_LOCKS, 0x00)) #print("App: get doorlocks() is_sup: " + str(is_sup)) diags_capability = cmd_obj.get_capability(Identifiers.DIAGNOSTICS) is_sup = diags_capability.is_supported( msg_type.MsgType(Identifiers.DIAGNOSTICS, 0x00)) #print("App: diags get() is_sup: " + str(is_sup)) vehsts_capability = cmd_obj.get_capability( Identifiers.VEHICLE_STATUS) if vehsts_capability is not None: is_sup = vehsts_capability.is_supported( msg_type.MsgType(Identifiers.VEHICLE_STATUS, 0x00)) #print("App: is_sup: " + str(is_sup)) #else: #print("Vehicle Status Capability not present") # Example: Permissions Check # Test Permission for VehicleStatus READ vehsts_permission_bitlocation = PermissionLocation.locationfor( Identifiers.VEHICLE_STATUS, PermissionType.READ) # get access_certificate, get permissions, serial mocked access_cert = hmkit_inst.get_certificate(None) permissions = access_cert.get_permissions() # check is_allowed from permissions. isallowed = permissions.is_allowed(vehsts_permission_bitlocation) #print("Permission check for Vehicle Status. isAllowed: ", isallowed) return 1
def __init__(self, msgbytes, pricetariffs): """ Constructs Set HomeCharger Price Tariff message bytes and construct instance. :param HomeChargeTariff pricetariff: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER,0x01) if msgbytes is None: # Construction # construct case super().__init__(None, self.msg_type) self.propblocks = [] if isinstance(pricetariffs, list) and isinstance(pricetariffs[0], HomeChargeTariff): for pricetariff in pricetariffs: prop_pricetariff = hmproperty.HmProperty(None, SetHomeChargerPriceTariff.PRICE_TARIFF_PROP_ID, pricetariff.get_valuebytes(), None, None) self.propblocks.append(prop_pricetariff) elif isinstance(pricetariffs, HomeChargeTariff): prop_pricetariff = hmproperty.HmProperty(None, SetHomeChargerPriceTariff.PRICE_TARIFF_PROP_ID, pricetariffs.get_valuebytes(), None, None) self.propblocks.append(prop_pricetariff) super().create_bytes(self.propblocks) else: log.error("invalid argument type") return
def __init__(self, msgbytes, reductiontimes): """ Construct Set Reduction Charging Current Times Timers message bytes and Construct an instance :param bytearray msgbytes: only required for Parse case. pass None :param list of ReductionTime: list of :class:`properties.value.charging.reduction_time.ReductionTime` """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CHARGING, 0x01) self.set_reduc_chargecurr = [] if msgbytes is not None: # message bytes parsing log.debug("parsing case not required for link device ") elif isinstance(reductiontimes, list) and isinstance( reductiontimes[0], ReductionTime): # construct message bytes case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.info("arg: " + str(reductiontimes)) for reductiontime in reductiontimes: setreduc_chargecurr = hmproperty.HmProperty( None, SetReductionChargingCurrentTimes.reduction_time_prop_id, reductiontime, None, None) self.set_reduc_chargecurr.append(setreduc_chargecurr) super().create_bytes(self.set_reduc_chargecurr) else: log.error("invalid argument type") return
def __init__(self, arg): """ Constructs Set Charge Mode message bytes and constructs Instance :param enum arg: :Enum class:`..properties.value.charge_mode.ChargeMode` """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CHARGING, 0x01) if isinstance(arg, Enum): # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.info("arg: " + str(arg)) self.charge_mode = hmproperty.HmProperty( None, SetChargeMode.charge_mode_prop_id, arg, None, None) super().create_bytes(self.charge_mode) elif isinstance(arg, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(arg) log.info( "parse case not required in Link device and not implemented") else: log.error("invalid argument type") return
def __init__(self, arg): """ Constructs LockUnlockDoor message bytes and constructs a Instance :param properties.value.lock.Lock arg: :class:`properties.value.lock.Lock` """ log.debug(" ") log.debug("Identifiers.DOOR_LOCKS " + str(Identifiers.DOOR_LOCKS) + " Type: " + str(type(Identifiers.DOOR_LOCKS))) log.debug("Identifiers.DOOR_LOCKS.value " + str(Identifiers.DOOR_LOCKS.value)) self.msg_type = msg_type.MsgType(Identifiers.DOOR_LOCKS, 0x01) if isinstance(arg, Lock): # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.debug("__init__ arg: " + str(arg)) self.doorlock = hmproperty.HmProperty( None, LockUnlockDoors.lockst_prop_id, arg, None, None) super().create_bytes(self.doorlock) elif isinstance(arg, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(arg) log.info("__init__ parsing not implemented for link device") else: log.error("invalid argument type") return
def __init__(self, arg): """ Constructs Start Stop Charging and constructs an instance :param arg : bool :rtype: None """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CHARGING, 0x01) if isinstance(arg, bool): # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.debug("arg: " + str(arg)) self.charging_state = hmproperty.HmProperty( None, StartStopCharging.charging_state_prop_id, arg, None, None) super().create_bytes(self.charging_state) elif isinstance(arg, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(arg) log.debug( "StartStopCharging parse case not required in Link and not implemented" ) else: log.debug("invalid argument type") return
def __init__(self, arg): """ Constructs Set Charge Limit message bytes and construct instance. :param float arg: Charge Limit value """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CHARGING, 0x01) if isinstance(arg, float): # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.info("arg: " + str(arg)) double_val = DoubleHm(arg) self.charge_limit = hmproperty.HmProperty( None, SetChargeLimit.charge_limit_prop_id, double_val, None, None) super().create_bytes(self.charge_limit) elif isinstance(arg, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(arg) log.info("parse case not required in Link and not implemented") else: log.error("invalid argument type") return
def __init__(self, lock, pos): """ Constructs Control Gas Flap message bytes and constructs Instance :param enum lock: :Enum class:`properties.value.lock.Lock` :param enum pos: :Enum class:`properties.value.position.Position` """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.FUELING, 0x01) super().__init__(None, self.msg_type) self.propblocks = [] if isinstance(lock, Lock) and isinstance(pos, Position): propblock = hmproperty.HmProperty(None, ControlGasFlap.GAS_FLAP_LOCK, lock, None, None) self.propblocks.append(propblock) propblock = hmproperty.HmProperty(None, ControlGasFlap.GAS_FLAP_POS, pos, None, None) self.propblocks.append(propblock) super().create_bytes(self.propblocks) else: log.error("invalid argument type") return
def __init__(self, ignition_on, msgbytes=None): """ Constructs TurnIgnitionOnOff message bytes and constructs a Instance :param bool: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.ENGINE,0x01) if ignition_on is not None: # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.debug("__init__ ignition_on: " + str(ignition_on)) propblock = hmproperty.HmProperty(None, TurnIgnitionOnOff.IGNITION_IDENTIFIER, ignition_on, None, None) super().create_bytes(propblock) elif isinstance(msgbytes, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(msgbytes) log.info("__init__ parsing not implemented for link device") else: log.error("invalid argument type") return
def __init__(self, arg): """ Construct Set Parking Brake State message bytes and Construct an instance :param bool arg: True - Activate, False - Inactivate """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.PARKING_BRAKE, 0x01) if isinstance(arg, bool): # construct case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.info("arg: " + str(arg)) self.parkbrakestate = hmproperty.HmProperty( None, SetParkingBrakeState.parkingbrake_state_prop_id, arg, None, None) super().create_bytes(self.parkbrakestate) elif isinstance(arg, (bytes, bytearray)): # NOTE: parsing case NOT needed for link device super().__init__(arg) log.info("parse case not required in Link and not implemented") else: log.error("invalid argument type") return
def __init__(self): """ Constructs Get Lock State message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.DOOR_LOCKS, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Ignition State :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.ENGINE, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Vehicle Time :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.VEHICLE_TIME, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Gas Flap State message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.FUELING, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Trunk State :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.TRUNK_ACCESS,0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Parking Break State message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.PARKING_BRAKE, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Capabilities message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CAPABILITIES, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self): """ Constructs Get Home Charger State message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER, 0x00) super().__init__(None, self.msg_type) super().create_bytes(None) return
def __init__(self, authenticate): """ Constructs Authenticate/Expire Authentication Home Charger message bytes and constructs Instance :param bool authenticate: true for authenticate, and false for expire """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER, 0x01) super().__init__(None, self.msg_type) if authenticate is not None: self.propblock = hmproperty.HmProperty(None, AuthenticateHomeCharger.AUTHENTICATE_EXPIRE, authenticate, None, None) super().create_bytes(self.propblock) else: log.error("invalid argument type") return
def __init__(self, activate): """ Constructs Activate/Deactivate Home Solar Charger message bytes and constructs Instance :param bool activate: true for activate and false for inactive """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER, 0x01) super().__init__(None, self.msg_type) if activate is not None: self.propblock = hmproperty.HmProperty(None, ActivateHomeChargerSolar.ACTIVATE_SOLAR, activate, None, None) super().create_bytes(self.propblock) else: log.error("invalid argument type") return
def __init__(self, enable): """ Constructs Enable/Disable Home Charger Wifi HotSpot message bytes and constructs Instance :param bool activate: true for enable, and false for disable """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER, 0x01) super().__init__(None, self.msg_type) if enable is not None: self.propblock = hmproperty.HmProperty(None, EnableHomeChargerWifiHotSpot.WIFI_HOTSPOT, enable, None, None) super().create_bytes(self.propblock) else: log.error("invalid argument type") return
def __init__(self): """ Constructs Wake Up message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.WAKE_UP, 0x01) super().__init__(None, self.msg_type) self.propblocks = [] propblock = hmproperty.HmProperty(None, WakeUp.WAKE_UP_PROP_ID, 0x00, None, None) self.propblocks.append(propblock) super().create_bytes(self.propblocks) return
def __init__(self, current): """ Constructs HomeCharge SetCharge Current message bytes and constructs Instance :param float current: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HOME_CHARGER, 0x01) super().__init__(None, self.msg_type) if current is not None: self.propblock = hmproperty.HmProperty(None, SetHomeChargeCurrent.CHARGE_CURRENT, current, None, None) super().create_bytes(self.propblock) else: log.error("invalid argument type") return
def __init__(self, msgbytes, charge_timers): """ Construct Set Charging Timers message bytes and Construct an instance :param bytearray msgbytes: only required for Parse case else pass None :param list of ChargingTimer: list of :class:`properties.value.charging.charge_timer.ChargingTimer` """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CHARGING,0x01) if isinstance(charge_timers, list) and isinstance(charge_timers[0], ChargingTimer): # construct message bytes case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.info("arg: " + str(charge_timers)) self.set_chargingtimers = [] for charge_timer in charge_timers: set_chargingtimer = hmproperty.HmProperty(None, SetChargingTimers.charge_timer_prop_id, charge_timer, None, None) self.set_chargingtimers.append(set_chargingtimer) super().create_bytes(self.set_chargingtimers) elif msgbytes is not None: # message bytes parsing super().__init__(msgbytes) self.charging_timers = [] props = super().getProperties() prop_itr = self.properties_iterator while self.properties_iterator.has_next() == True: hmprop = self.properties_iterator.next() # TODO if hmprop.getproperty_identifier() == charge_timer_prop_id: log.debug("Charge Timer") if hmprop.getcomponent_valuebytes() is not None: chargetimer = charge_timer.ChargingTimer(hmprop.getcomponent_valuebytes(), None, None) self.charging_timers.append(chargetimer) else: log.error("invalid argument type") return
def __init__(self, rate): """ Constructs Send Heart Rate message bytes and constructs Instance :param rate: int """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.HEART_RATE, 0x01) super().__init__(None, self.msg_type) if isinstance(rate, int): self.prop_heartrate = hmproperty.HmProperty( None, SendHeartRate.HEART_RATE, rate, None, None) super().create_bytes(self.prop_heartrate) else: log.error("invalid argument type") return
def __init__(self): """ Constructs Clear Notification message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.NOTIFICATIONS, 0x01) super().__init__(None, self.msg_type) self.propblocks = [] propblock = hmproperty.HmProperty(None, ClearNotification.CLEAR_NOTIFICATION, 0x00, None, None) self.propblocks.append(propblock) super().create_bytes(self.propblocks) return
def __init__(self, text, actionitems, msgbytes=None): """ Constructs Notification message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.NOTIFICATIONS, 0x01) if text is not None: # construct message bytes case super().__init__(None, self.msg_type) # create a property # TODO, get timestamp and failure from arg log.debug("__init__ text: " + text + " actionitems: " + str(actionitems)) self.propblocks = [] propblock = hmproperty.HmProperty(None, Notification.IDENTIFIER_TEXT, text, None, None) self.propblocks.append(propblock) if isinstance(actionitems, list) and isinstance( actionitems[0], ActionItem): for actionitem in actionitems: set_chargingtimer = hmproperty.HmProperty( None, Notification.IDENTIFIER_ACTION_ITEM, actionitem, None, None) self.propblocks.append(set_chargingtimer) super().create_bytes(self.propblocks) elif msgbytes is not None: # parsing case super().__init__(msgbytes) #log.info("__init__ parsing not implemented for link device") else: log.error("invalid argument type") return
def __init__(self, identifier): """ Constructs Get Capability message :param identifier: hmkit.autoapi.identifiers.Identifiers """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.CAPABILITIES,0x02) super().__init__(None, self.msg_type) if identifier is not None: print("GetCapability() identifier.value: " + str(identifier.value)) identifier_bytes = identifier.value #print("GetCapability() id bytes: " + str(identifier_bytes)) self.getcap = hmproperty.HmProperty(None, GetCapability.getcapability_prop_id, identifier_bytes, None, None) super().create_bytes(self.getcap) return
def __init__(self): """ Constructs End Parking message :param None: """ log.debug(" ") self.msg_type = msg_type.MsgType(Identifiers.PARKING_TICKET, 0x01) super().__init__(None, self.msg_type) self.status = None properties = [] # Parking Status. Constant Value 0x00 (Ended) self.status = hmproperty.HmProperty( None, EndParking.PARKING_STATUS_IDENTIFIER, 0x00, None, None) log.debug("status: " + str(self.status)) properties.append(self.status) super().create_bytes(properties) return
def __init__(self, msgbytes, operator_name, operatorticket_id, start_time, end_time): """ Constructs Start parking message and constructs an instance :param msgbytes : bytearray :param operator_name : str :param operatorticket_id : str :param start_date : datetime.datetime :param end_date : datetime.datetime :rtype: None """ print(" ") self.msg_type = msg_type.MsgType(Identifiers.PARKING_TICKET, 0x01) super().__init__(None, self.msg_type) self.status = None self.operator_name = None self.ticket_id = None self.start_time = None self.end_time = None # Message Construction Case if msgbytes is None: properties = [] # Parking Status. Constant Value 0x01 (Started) self.status = hmproperty.HmProperty( None, StartParking.PARKING_STATUS_IDENTIFIER, 0x01, None, None) log.debug("status: " + str(self.status)) properties.append(self.status) # construct case if isinstance(operator_name, str): # create a property # TODO, get timestamp and failure from arg log.debug("operator_name: " + str(operator_name)) self.operator_name = hmproperty.HmProperty( None, StartParking.OPERATOR_NAME_IDENTIFIER, operator_name, None, None) properties.append(self.operator_name) else: log.debug( "wrong parameter type for operator_name Expected Str but : " + str(type(operator_name))) if isinstance(operatorticket_id, str): # create a property # TODO, get timestamp and failure from arg log.debug("ticket_id: " + str(operatorticket_id)) self.ticket_id = hmproperty.HmProperty( None, StartParking.OPERATOR_TICKET_ID_IDENTIFIER, operatorticket_id, None, None) #super().create_bytes(self.parkbrakestate) properties.append(self.ticket_id) else: log.debug( "wrong parameter type for ticket_id Expected Str but : " + str(type(ticket_id))) if isinstance(start_time, datetime): # create a property # TODO, get timestamp and failure from arg log.debug("start_time: " + str(start_time)) self.start_time = hmproperty.HmProperty( None, StartParking.TICKET_START_TIME_IDENTIFIER, start_time, None, None) #super().create_bytes(self.parkbrakestate) properties.append(self.start_time) else: log.debug( "wrong parameter type for start_time Expected datetime but : " + str(type(start_time))) if isinstance(end_time, datetime): # create a property # TODO, get timestamp and failure from arg log.debug("end_time: " + str(end_time)) self.end_time = hmproperty.HmProperty( None, StartParking.TICKET_END_TIME_IDENTIFIER, end_time, None, None) #super().create_bytes(self.parkbrakestate) properties.append(self.end_time) else: log.debug( "wrong parameter type for end_time Expected datetime but : " + str(type(end_time))) super().create_bytes(properties) else: log.debug("parsing case not required for link device ") return