Closed Murray2015 closed 3 years ago
I see what you have done. Rather than making the various controls/sensors child classes of your serial class, I would pass the same instance of the serial class to the various sensors. You do that in the ControlBox class. This reflects the relationship more acurately, ie. the FanControl isn't a SerialConnection but has one.
def __init__(self):
self._a = None
@property
def a(self):
return self._a
@a.setter
def a(self,val):
self._a = float(v)
The setter is called when you do something like inst.a=1 and fails as you would expect when you do inst.a='hello' In your case the setter is used to send a command to the serial as well as storing the current val in the private variable. Your case is a bit more complicated because you are calling a coroutine. I would expect that
@a.setter
async def a(self,val):
await something
and then
await inst.a = 1
works
ah, I see you realised that in your second patch. Excellent.
BTW, do you send strings to serial or shouldn't that be bytes? Strings are unicode
Main headlines: have made 3 extra classes to hold current, voltage and fan sensors.
Questions