(Dec-18-2022, 06:26 PM)deanhystad Wrote: I prefer unpacking to indexing.
message_type, id, state, status = output.split(',') occupancy_sensor1 = Device(id, status)This code raises an exception if self.status is not '3' or '4'
return f'{self.dev_id} - {status}'I agree with menator about how to save information like status. If status should be 'Active' or 'Inactive', use these in the class. If status should be 3 or 4, define an enumeration that gives these numerical values names. I don't see why status would ever be '3' or '4' other than that is how it is received in a message.
I like the idea of unpacking. I'll have a look at that. The monitoring system I'm writing the code for uses a 3 to determine an Active state (or contact closed) and a 4 to determine the inactive state (contact open) so in theory it should never be anything else but I'm definitely a fan of build something that is robust.
I'm quite new to Python so all of this is great, helpful info. Thanks.