Read the container level and dose schedule of dosing pumps #1
Loading…
Reference in a new issue
No description provided.
Delete branch "gulaschcowboy/dose-container"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Library side of r3pek/ha-mobius#5, as requested in the review there: the dosing pump (DoseV1, Versa) protocol code moves from the integration into python-mobius.
FullPollResult.dose(DoseInfo): remaining volume, container size, dispensed today, container monitor and sensor type, dosing halt state, and the daily target and expected volume from the dose schedule.STATIC_POLL_ATTRIBUTES, so they're only read at the static refresh interval.ConfigurationCacheby its checksum, like the other schedules.get_dose_info(),set_container_volume()(also resets the remaining volume, like the app) andrefill_container().tests/test_dose.py), a CHANGELOG entry, and README/docs updates (DoseV1 is no longer listed as not implemented).The 7 BLE connection tests (
test_connection_cleanup,test_serial_identity,test_write_size) that fail locally also fail onmainhere, so they're unrelated.Thanks for moving this into the library, it fits in nicely. A few things before I merge:
Reuse the shared schedule point header.
DoseSchedulePoint.parsere-parses the start time and flags itself instead of using_PointBase._parse_header, which the light and pump points use. Could it subclass_PointBaselike they do, withtime_minutes/flagsfields and the decoded dose primitive? That keeps the three point types consistent and gives a dose schedule writer something to build on later.Pass the dose attributes by name.
_decode_dose_from_batchrelies on_DOSE_REQUESTSlisting the attributes in the same order asdecode_dose_info's arguments. Reordering the list, or adding an attribute in the middle, would silently swap fields. Passing them by name (e.g.current_volume_raw=first(C2Attribute.ContainerCurrentVolume), ...) avoids that.Attribute reference. Please add the new attributes to
documentation/14-attribute-reference.md:DailyDosage(2301),DoseSensorType(2305),ContainerMonitor(2310),ContainerVolume(2312),ContainerCurrentVolume(2313) andDoseHaltState(2322), with their encodings.Booleans pass the volume check, and the helper's name.
_dose_volume_bytesusesisinstance(volume_ul, int), andboolis a subclass ofint, soset_container_volume(True)writes a 1 µl container instead of raising. Something likeisinstance(volume_ul, bool) or not isinstance(volume_ul, int)fixes it. Theminimum=0default can go too, since both callers pass 1. Could you also rename it to_container_volume_to_bytes? It only packs container volumes, and "dose" in the name suggests it sets an amount to dispense.Require exactly one dose primitive per schedule point.
DoseSchedulePoint.parseaccepts any length of 3 + n × 9 bytes but only decodes the first primitive. A point should always be 12 bytes, so anything else should be rejected (len(data) != 3 + DOSE_PRIMITIVE_SIZE) rather than half-read. Otherwise an unexpected format would silently produce a wrong daily target instead of no target.Once these are in I'll merge and release, so the ha-mobius PR can go in after it.
DoseSchedulePointnow subclasses_PointBase(time_minutes,flags) and holds aDosePrimitiveValue(duration_s,volume_ul,flags) withparse()/encode(), like the light and pump points.start_minute,duration_minutes,volume_ulandconstantare properties, so the target calculations didn't change._decode_dose_from_batchpasses each attribute todecode_dose_info()by keyword;_DOSE_REQUESTSis only the request list now.DoseSensorType,ContainerMonitorTypeandDoseHaltStateenum tables._container_volume_to_bytes(), rejectsbool, and always requires at least 1 µl (theminimumparameter is gone). There's a test forset_container_volume(True).Same 7 BLE connection tests fail locally as on
main; everything else passes.