Skip to content

Conversation

@njooma
Copy link
Member

@njooma njooma commented Sep 3, 2025

This PR should supersede #993 and #982

Change the functionality of CameraMimeType so that it is not limited only to predetermined values, but has the ability to add CUSTOM values of CameraMimeType that can be used everywhere in the code.

CameraMimeType continues to behave as a str everywhere str is accepted, while having additional properties and methods, including name and value properties, which give it the same properties as the previous Enum-type.

This should prevent the mime-type changes from being a breaking change.

@njooma njooma requested a review from a team as a code owner September 3, 2025 19:25
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base is_moving
board gpio_pin_by_name
button push
genericcomponent do_command
camera get_image
encoder get_position
motor is_moving
sensor get_readings
servo get_position
switch get_position
arm get_end_position
gantry get_lengths
gripper is_moving
movement_sensor get_linear_acceleration
input_controller get_controls
audio get_properties
pose_tracker get_poses
power_sensor get_power
motion get_pose
vision get_properties
mlmodel metadata
genericservice do_command
slam get_point_cloud_map

@njooma njooma requested review from bhaney, hexbabe and stuqdog September 3, 2025 19:26
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, lgtm!

Comment on lines +12 to +23
class _FrozenClassAttributesMeta(type):
"""
A metaclass that prevents the reassignment of existing class attributes.
"""

def __setattr__(cls, name: str, value: Any):
# Check if the attribute `name` already exists on the class
if name in cls.__dict__:
# If it exists, raise an error to prevent overwriting
raise AttributeError(f"Cannot reassign constant '{name}'")
# If it's a new attribute, allow it to be set
super().__setattr__(name, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh this is clever

raise NotImplementedError()

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> List[Geometry]:
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> Sequence[Geometry]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why these Sequence changes? Does it type-hint grpc repeated sets better?

Copy link
Member Author

@njooma njooma Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea exactly -- a superset of list that allows us to save some casts

assert img4.width is None
assert img4.height is None

img5 = ViamImage(b"data", CameraMimeType.CUSTOM(self.UNSUPPORTED_MIME_TYPE))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we test to_proto on an unsupported mime somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@njooma njooma requested a review from hexbabe September 4, 2025 17:52
Copy link
Member

@hexbabe hexbabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@njooma njooma merged commit 076c83a into viamrobotics:main Sep 5, 2025
13 checks passed
@njooma njooma deleted the camera-mime-with-custom branch September 5, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants