Skip to content

Commit

Permalink
Make DatapointSubscriptionFilterProperties properties immutable (#1324
Browse files Browse the repository at this point in the history
)
  • Loading branch information
haakonvt authored Aug 24, 2023
1 parent 0f3baef commit c0c8942
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions cognite/client/data_classes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ def dump(self, camel_case: bool = False) -> Dict[str, Any]:


class EnumProperty(Enum):
@staticmethod
def _generate_next_value_(name: str, *_: Any) -> str:
# Allows the use of enum.auto() for member values avoiding camelCase typos
return to_camel_case(name)

def as_reference(self) -> list[str]:
return [self.value]

Expand Down Expand Up @@ -668,9 +673,7 @@ def load(
nulls=data[2], # type: ignore[misc]
)
elif isinstance(data, (str, list, EnumProperty)):
return cls(
property=data,
)
return cls(property=data)
else:
raise ValueError(f"Unable to load {cls.__name__} from {data}")

Expand All @@ -685,10 +688,7 @@ def dump(self, camel_case: bool = False) -> dict[str, Any]:
else:
raise ValueError(f"Unable to dump {type(self).__name__} with property {prop}")

output: dict[str, str | list[str]] = {
"property": prop,
"order": self.order,
}
output: dict[str, str | list[str]] = {"property": prop, "order": self.order}
if self.nulls is not None:
output["nulls"] = self.nulls
return output
Expand Down
28 changes: 15 additions & 13 deletions cognite/client/data_classes/datapoints_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
from dataclasses import dataclass
from enum import auto
from typing import TYPE_CHECKING, Any, Optional, Type

from cognite.client.data_classes import Datapoints, filters
Expand All @@ -11,6 +12,7 @@
CogniteResource,
CogniteResourceList,
CogniteUpdate,
EnumProperty,
PropertySpec,
T_CogniteResource,
)
Expand Down Expand Up @@ -369,17 +371,17 @@ def _metadata(key: str) -> list[str]:
return ["metadata", key]


class DatapointSubscriptionFilterProperties:
description = ["description"]
external_id = ["externalId"]
class DatapointSubscriptionFilterProperties(EnumProperty):
description = auto()
external_id = auto()
metadata = _metadata
name = ["name"]
unit = ["unit"]
asset_id = ["assetId"]
asset_root_id = ["assetRootId"]
created_time = ["createdTime"]
data_set_id = ["dataSetId"]
id = ["id"]
last_updated_time = ["lastUpdatedTime"]
is_step = ["isStep"]
is_string = ["isString"]
name = auto() # type: ignore [assignment]
unit = auto()
asset_id = auto()
asset_root_id = auto()
created_time = auto()
data_set_id = auto()
id = auto()
last_updated_time = auto()
is_step = auto()
is_string = auto()
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def test_update_filter_defined_subscription(self, cognite_client: CogniteClient)
# Arrange
f = filters
p = DatapointSubscriptionFilterProperties
numerical_timeseries = f.And(
f.Equals(p.is_string, False),
)
numerical_timeseries = f.And(f.Equals(p.is_string, False))

new_subscription = DataPointSubscriptionCreate(
external_id="PYSDKFilterDefinedDataPointSubscriptionUpdateTest",
Expand Down

0 comments on commit c0c8942

Please sign in to comment.