Skip to content

Commit 39f1329

Browse files
committed
map channel description to display field
1 parent 7760402 commit 39f1329

5 files changed

Lines changed: 30 additions & 22 deletions

File tree

python/lib/sift_client/_tests/sift_types/test_channel.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def mock_channel(mock_client):
2222
bit_field_elements=[],
2323
enum_types={},
2424
asset_id="test_asset_id",
25-
display_description="display description",
26-
display_unit="m/s",
2725
metadata={},
2826
active=True,
2927
created_date=datetime.now(timezone.utc),
@@ -228,7 +226,7 @@ def test_update_calls_client_and_updates_self(self, mock_channel, mock_client):
228226
with MagicMock() as mock_update:
229227
mock_channel._update = mock_update
230228

231-
update = ChannelUpdate(display_description="new description")
229+
update = ChannelUpdate(description="new description")
232230
result = mock_channel.update(update)
233231

234232
mock_client.channels.update.assert_called_once_with(channel=mock_channel, update=update)
@@ -278,8 +276,8 @@ class TestChannelUpdate:
278276
def test_fields_map_to_correct_proto_fields(self):
279277
"""Each ChannelUpdate field targets its matching Channel proto field and mask path."""
280278
update = ChannelUpdate(
281-
display_description="new description",
282-
display_unit="volts",
279+
description="new description",
280+
unit="volts",
283281
metadata={"source": "pytest"},
284282
active=False,
285283
)
@@ -288,14 +286,17 @@ def test_fields_map_to_correct_proto_fields(self):
288286
proto, mask = update.to_proto_with_mask()
289287

290288
assert proto.channel_id == "test_channel_id"
289+
# description/unit write the display override fields, the only ones the
290+
# server allows UpdateChannel to mutate.
291291
assert proto.display_description == "new description"
292-
# display_unit is renamed onto the proto's display_unit_id field.
293292
assert proto.display_unit_id == "volts"
294293
assert {md.key.name: md.string_value for md in proto.metadata} == {"source": "pytest"}
295294
assert proto.active is False
295+
# The server's update mask accepts "display_units" (not "display_unit_id")
296+
# for the unit; see channel_service.go UpdateChannel.
296297
assert set(mask.paths) == {
297298
"display_description",
298-
"display_unit_id",
299+
"display_units",
299300
"metadata",
300301
"active",
301302
}

python/lib/sift_client/_tests/sift_types/test_results.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ def _channel(name: str) -> Channel:
372372
bit_field_elements=[],
373373
enum_types={},
374374
asset_id="asset_1",
375-
display_description="",
376-
display_unit="",
377375
active=True,
378376
created_date=now,
379377
modified_date=now,

python/lib/sift_client/resources/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async def update(
201201
Args:
202202
channel: The Channel or channel ID to update.
203203
update: Updates to apply to the Channel. See ChannelUpdate for the updatable fields
204-
(display description, display unit, metadata, and active status).
204+
(description, unit, metadata, and active status).
205205
206206
Returns:
207207
The updated Channel.

python/lib/sift_client/resources/sync_stubs/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class ChannelsAPI:
564564
Args:
565565
channel: The Channel or channel ID to update.
566566
update: Updates to apply to the Channel. See ChannelUpdate for the updatable fields
567-
(display description, display unit, metadata, and active status).
567+
(description, unit, metadata, and active status).
568568
569569
Returns:
570570
The updated Channel.

python/lib/sift_client/sift_types/channel.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ class Channel(BaseType[ChannelProto, "Channel"]):
254254
bit_field_elements: list[ChannelBitFieldElement] = Field(default_factory=list)
255255
enum_types: dict[str, int] = Field(default_factory=dict)
256256
asset_id: str
257-
display_description: str
258-
display_unit: str
259257
metadata: dict[str, str | float | bool] = Field(default_factory=dict)
260258
active: bool
261259
created_date: datetime
@@ -284,15 +282,16 @@ def _from_proto(cls, proto: ChannelProto, sift_client: SiftClient | None = None)
284282
id_=proto.channel_id,
285283
name=proto.name,
286284
data_type=ChannelDataType(proto.data_type),
287-
description=proto.description,
288-
unit=proto.unit_id,
285+
# Prefer the user-set display override, falling back to the canonical
286+
# value set at channel creation. This mirrors how the Sift app resolves
287+
# these (displayDescription || description, displayUnit || unit).
288+
description=proto.display_description or proto.description,
289+
unit=proto.display_unit_id or proto.unit_id,
289290
bit_field_elements=[
290291
ChannelBitFieldElement._from_proto(el) for el in proto.bit_field_elements
291292
],
292293
enum_types=cls._enum_types_from_proto_list(proto.enum_types), # type: ignore
293294
asset_id=proto.asset_id,
294-
display_description=proto.display_description,
295-
display_unit=proto.display_unit_id,
296295
metadata=metadata_proto_to_dict(proto.metadata), # type: ignore
297296
active=proto.active,
298297
created_date=proto.created_date.ToDatetime(tzinfo=timezone.utc),
@@ -383,17 +382,27 @@ def runs(self) -> list[Run]:
383382

384383

385384
class ChannelUpdate(ModelUpdate[ChannelProto]):
386-
"""Model of the Channel fields that can be updated."""
385+
"""Model of the Channel fields that can be updated.
387386
388-
display_description: str | None = None
389-
display_unit: str | None = None
387+
A channel's canonical description and unit are set at creation and are immutable
388+
afterward. Updating ``description`` or ``unit`` writes the channel's display
389+
override (``display_description`` / ``display_unit_id``), which is the value the
390+
Sift app shows in place of the canonical one.
391+
"""
392+
393+
description: str | None = None
394+
unit: str | None = None
390395
metadata: dict[str, str | float | bool] | None = None
391396
active: bool | None = None
392397

393398
_to_proto_helpers: ClassVar[dict[str, MappingHelper]] = {
394-
"display_unit": MappingHelper(
399+
"description": MappingHelper(
400+
proto_attr_path="display_description",
401+
update_field="display_description",
402+
),
403+
"unit": MappingHelper(
395404
proto_attr_path="display_unit_id",
396-
update_field="display_unit_id",
405+
update_field="display_units",
397406
),
398407
"metadata": MappingHelper(
399408
proto_attr_path="metadata",

0 commit comments

Comments
 (0)