Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class help
#6
(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.
Reply


Messages In This Thread
Class help - by txrx - Dec-18-2022, 05:01 PM
RE: Class help - by txrx - Dec-18-2022, 05:09 PM
RE: Class help - by menator01 - Dec-18-2022, 05:31 PM
RE: Class help - by txrx - Dec-18-2022, 06:16 PM
RE: Class help - by deanhystad - Dec-18-2022, 06:26 PM
RE: Class help - by txrx - Dec-18-2022, 07:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020