Skip to content

Commit

Permalink
[IMP] web_widget_remote_measure: non stop read
Browse files Browse the repository at this point in the history
TT49230
  • Loading branch information
chienandalu committed May 24, 2024
1 parent c603beb commit 295373f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions web_widget_remote_measure/models/remote_measure_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class RemoteMeasureDevice(models.Model):
required=True,
)
host = fields.Char(required=True)
instant_read = fields.Boolean(help="Read right on as the widget gets rendered")
non_stop_read = fields.Boolean(
help="Don't stop reading until the widget is disposed"
)
test_measure = fields.Float(default=0.0)
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ export const RemoteMeasureMixin = {
var icon = "fa-thermometer-empty";
var stream_success_counter = 20;
this._unstableMeasure();
// Don't keep going forever
for (let attemps_left = 1000; attemps_left > 0; attemps_left--) {
// Don't keep going forever unless non stop reading
for (
let attemps_left = this.remote_device_data.non_stop_read ? Infinity : 1000;
attemps_left > 0;
attemps_left--
) {
const processed_data = await this._read_from_device_tcp();
if (!processed_data) {
continue;
Expand All @@ -123,6 +127,9 @@ export const RemoteMeasureMixin = {
this._awaitingMeasure();
this._recordMeasure();
break;
} else if (this.remote_device_data.non_stop_read) {
stream_success_counter = 20;
this._recordMeasure();
}
if (stream_success_counter) {
--stream_success_counter;
Expand Down Expand Up @@ -402,6 +409,17 @@ export const RemoteMeasure = FieldFloat.extend(RemoteMeasureMixin, {
this.$el.prepend(this.$start_measure, this.$stop_measure);
return def;
},
/**
* Read right on if configured
* @override
*/
start() {
this._super(...arguments).then(() => {
if (this.remote_device_data.instant_read) {
this.measure();
}
});
},
/**
* Ensure that the socket is allways closed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<field name="connection_mode" />
</group>
</group>
<group>
<group>
<field name="instant_read" />
<field name="non_stop_read" />
</group>
</group>
</sheet>
</form>
</field>
Expand Down

0 comments on commit 295373f

Please sign in to comment.