pub struct RiDevice { /* private fields */ }Expand description
Smart device representation
This struct represents a smart device in the Ri system, including its status, capabilities, health metrics, and lifecycle information.
Implementations§
Source§impl RiDevice
impl RiDevice
Sourcepub fn new(name: String, device_type: RiDeviceType) -> Self
pub fn new(name: String, device_type: RiDeviceType) -> Self
Sourcepub fn device_type(&self) -> RiDeviceType
pub fn device_type(&self) -> RiDeviceType
Sourcepub fn status(&self) -> RiDeviceStatus
pub fn status(&self) -> RiDeviceStatus
Sourcepub fn capabilities(&self) -> &RiDeviceCapabilities
pub fn capabilities(&self) -> &RiDeviceCapabilities
Gets a reference to the device capabilities
§Returns
A reference to the RiDeviceCapabilities structure
Sourcepub fn health_metrics(&self) -> &RiDeviceHealthMetrics
pub fn health_metrics(&self) -> &RiDeviceHealthMetrics
Gets a reference to the device health metrics
§Returns
A reference to the RiDeviceHealthMetrics structure
Sourcepub fn set_status(&mut self, status: RiDeviceStatus)
pub fn set_status(&mut self, status: RiDeviceStatus)
Sets the device status and updates the last seen timestamp
§Parameters
status: The new status to set
Sourcepub fn update_health_metrics(&mut self, metrics: RiDeviceHealthMetrics)
pub fn update_health_metrics(&mut self, metrics: RiDeviceHealthMetrics)
Updates the device health metrics and last seen timestamp
§Parameters
metrics: The new health metrics to set
Sourcepub fn increment_error_count(&mut self)
pub fn increment_error_count(&mut self)
Increments the device error count and updates the last seen timestamp
Sourcepub fn update_throughput(&mut self, throughput: u64)
pub fn update_throughput(&mut self, throughput: u64)
Updates the device throughput and last seen timestamp
§Parameters
throughput: The new throughput value in operations per second
Sourcepub fn with_capabilities(self, capabilities: RiDeviceCapabilities) -> Self
pub fn with_capabilities(self, capabilities: RiDeviceCapabilities) -> Self
Sourcepub fn set_location(&mut self, location: String)
pub fn set_location(&mut self, location: String)
Sourcepub fn add_metadata(&mut self, key: String, value: String)
pub fn add_metadata(&mut self, key: String, value: String)
Sourcepub fn update_last_seen(&mut self)
pub fn update_last_seen(&mut self)
Updates the last seen timestamp to the current time
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Checks if the device is available for allocation
A device is available if its status is Available and it has no current allocation.
§Returns
true if the device is available, false otherwise
Sourcepub fn is_allocated(&self) -> bool
pub fn is_allocated(&self) -> bool
Checks if the device is currently allocated
§Returns
true if the device is allocated, false otherwise
Sourcepub fn release(&mut self)
pub fn release(&mut self)
Releases the device from its current allocation
This method clears the allocation ID and sets the device status to Available if it was Busy.
Sourcepub fn remove_tag(&mut self, tag: &str) -> bool
pub fn remove_tag(&mut self, tag: &str) -> bool
Sourcepub fn get_allocation_id(&self) -> Option<&str>
pub fn get_allocation_id(&self) -> Option<&str>
Gets the current allocation ID if the device is allocated
§Returns
An Option<&str> containing the allocation ID if the device is allocated, None otherwise
Sourcepub fn health_score(&self) -> u8
pub fn health_score(&self) -> u8
Calculates a simple health score based on device status (0-100)
This method returns a basic health score based solely on the device status.
§Returns
A health score between 0 (worst) and 100 (best)
Sourcepub fn is_responsive(&self, timeout_secs: i64) -> bool
pub fn is_responsive(&self, timeout_secs: i64) -> bool
Sourcepub fn dynamic_health_score(&self, health_metrics: &RiDeviceHealthMetrics) -> u8
pub fn dynamic_health_score(&self, health_metrics: &RiDeviceHealthMetrics) -> u8
Calculates a dynamic health score based on multiple factors (0-100)
This method calculates a comprehensive health score based on device status, CPU usage, memory usage, temperature, and error count.
§Parameters
health_metrics: Current health metrics for the device
§Returns
A dynamic health score between 0 (worst) and 100 (best)
Sourcepub fn is_healthy(
&self,
health_metrics: &RiDeviceHealthMetrics,
timeout_secs: i64,
) -> bool
pub fn is_healthy( &self, health_metrics: &RiDeviceHealthMetrics, timeout_secs: i64, ) -> bool
Checks if the device is healthy based on multiple criteria
A device is considered healthy if it is responsive, has a good health score, and is not in an error or offline state.
§Parameters
health_metrics: Current health metrics for the devicetimeout_secs: Maximum number of seconds since last seen for the device to be considered responsive
§Returns
true if the device is healthy, false otherwise
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RiDevice
impl<'de> Deserialize<'de> for RiDevice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'py> IntoPyObject<'py> for RiDevice
impl<'py> IntoPyObject<'py> for RiDevice
Source§impl PyClassImpl for RiDevice
impl PyClassImpl for RiDevice
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = c"Smart device representation\n\nThis struct represents a smart device in the Ri system, including its status, capabilities,\nhealth metrics, and lifecycle information.\x00"
const RAW_DOC: &'static CStr = c"Smart device representation\n\nThis struct represents a smart device in the Ri system, including its status, capabilities,\nhealth metrics, and lifecycle information.\x00"
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<RiDevice>
type ThreadChecker = SendablePyClass<RiDevice>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for RiDevice
impl PyClassNewTextSignature for RiDevice
const TEXT_SIGNATURE: &'static str = "(name, device_type)"
Source§impl PyMethods<RiDevice> for PyClassImplCollector<RiDevice>
impl PyMethods<RiDevice> for PyClassImplCollector<RiDevice>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for RiDevice
impl PyTypeInfo for RiDevice
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for RiDevice
impl ExtractPyClassWithClone for RiDevice
Auto Trait Implementations§
impl Freeze for RiDevice
impl RefUnwindSafe for RiDevice
impl Send for RiDevice
impl Sync for RiDevice
impl Unpin for RiDevice
impl UnsafeUnpin for RiDevice
impl UnwindSafe for RiDevice
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more