Closed a112358132134 closed 3 years ago
The primary branch there at https://github.com/jeffsf/pyDE1/blob/alpha/src/pyDE1/dispatcher/dispatcher.py#L155 is that the scale needs to be present and in in the ready state before accepting commands from the external API:
if (got.connectivity_required['Scale']
and (scale_processor.scale is None
or not scale_processor.scale.is_ready)):
Since the API needs to support connecting to a scale, there is an exception in place to the "must be present and ready" check to allow either setting the ID directly or initiating setting of the ID indirectly through "find first".
Are you setting .is_ready
when initialization of the scale is complete?
https://github.com/jeffsf/pyDE1/blob/alpha/src/pyDE1/scale/atomax_skale_ii.py#L101
There's a little trickiness there with hold_notification=True
to allow the "call to super" without having it set the event, for when the specific class needs to do something after that call.
"Ready" vs. "connected" isn't a lot on a scale, but it is very significant on the DE1. You don't want to hammer it with the profile and other settings until it is ready (which may take on the order of a second).
Thank you for the quick and detailed response.
Here is my init function - I was setting the ready state, but looks like not per the current internal API which uses a new definition in scale.py. Great sleuthing!
async def standard_initialization(self, hold_notification=False):
await super(DecentScale, self).standard_initialization(
hold_notification=True)
if not hold_notification:
await self._event_connectivity.publish(
ConnectivityChange(
arrival_time=time.time(),
state=ConnectivityState.READY
)
)
I'll need to walkthrough the new scale.py and atomax_skale_ii.py and make sure I'm up-to-date in the other areas too.
Below is a command and response from the http server to tare the scale:
Below is a snip from pyDE1's console, showing slightly before and slightly after the command was executed, with clear evidence the scale is happily connected and transmitting:
As far as I can tell, on dispatcher.py line 161 it's saying the scale isn't connected if any of these three conditions aren't met:
got.resource is Resource.SCALE_ID
len(got.payload.keys()) == 1
'id' in got.payload or 'first_if_found' in got.payload
At this point,
got.resource
isResource.SCALE_TARE
and so it raisesDE1NotConnectedError("Scale not connected")
.Is this expected behaviour? Am I requesting a tare correctly?