#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0700;
pub const REVISION: u16 = 1;
pub const PICS: &str = "SETRF";
pub mod feature {
pub const PRICING: u32 = 1 << 0;
pub const FRIENDLY_CREDIT: u32 = 1 << 1;
pub const AUXILIARY_LOAD: u32 = 1 << 2;
pub const PEAK_PERIOD: u32 = 1 << 3;
pub const POWER_THRESHOLD: u32 = 1 << 4;
pub const RANDOMIZATION: u32 = 1 << 5;
}
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "PRICE",
name: "Pricing",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "FCRED",
name: "FriendlyCredit",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "AUXLD",
name: "AuxiliaryLoad",
conform: Conform::OPTIONAL,
},
Feature {
bit: 3,
code: "PEAKP",
name: "PeakPeriod",
conform: Conform::OPTIONAL,
},
Feature {
bit: 4,
code: "PWRTHLD",
name: "PowerThreshold",
conform: Conform::OPTIONAL,
},
Feature {
bit: 5,
code: "RNDM",
name: "Randomization",
conform: Conform::OPTIONAL,
},
];
pub mod attribute {
use crate::im::AttributeId;
pub const TARIFF_INFO: AttributeId = 0x00;
pub const TARIFF_UNIT: AttributeId = 0x01;
pub const START_DATE: AttributeId = 0x02;
pub const DAY_ENTRIES: AttributeId = 0x03;
pub const DAY_PATTERNS: AttributeId = 0x04;
pub const CALENDAR_PERIODS: AttributeId = 0x05;
pub const INDIVIDUAL_DAYS: AttributeId = 0x06;
pub const CURRENT_DAY: AttributeId = 0x07;
pub const NEXT_DAY: AttributeId = 0x08;
pub const CURRENT_DAY_ENTRY: AttributeId = 0x09;
pub const CURRENT_DAY_ENTRY_DATE: AttributeId = 0x0A;
pub const NEXT_DAY_ENTRY: AttributeId = 0x0B;
pub const NEXT_DAY_ENTRY_DATE: AttributeId = 0x0C;
pub const TARIFF_COMPONENTS: AttributeId = 0x0D;
pub const TARIFF_PERIODS: AttributeId = 0x0E;
pub const CURRENT_TARIFF_COMPONENTS: AttributeId = 0x0F;
pub const NEXT_TARIFF_COMPONENTS: AttributeId = 0x10;
pub const DEFAULT_RANDOMIZATION_OFFSET: AttributeId = 0x11;
pub const DEFAULT_RANDOMIZATION_TYPE: AttributeId = 0x12;
}
pub mod command {
use crate::im::CommandId;
pub const GET_TARIFF_COMPONENT: CommandId = 0x00;
pub const GET_TARIFF_COMPONENT_RESPONSE: CommandId = 0x00;
pub const GET_DAY_ENTRY: CommandId = 0x01;
pub const GET_DAY_ENTRY_RESPONSE: CommandId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum AuxiliaryLoadSettingEnum {
Off = 0,
On = 1,
None = 2,
}
impl AuxiliaryLoadSettingEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Off),
1 => Some(Self::On),
2 => Some(Self::None),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for AuxiliaryLoadSettingEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for AuxiliaryLoadSettingEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum BlockModeEnum {
NoBlock = 0,
Combined = 1,
Individual = 2,
}
impl BlockModeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::NoBlock),
1 => Some(Self::Combined),
2 => Some(Self::Individual),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for BlockModeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for BlockModeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum DayEntryRandomizationTypeEnum {
None = 0,
Fixed = 1,
Random = 2,
RandomPositive = 3,
RandomNegative = 4,
}
impl DayEntryRandomizationTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::None),
1 => Some(Self::Fixed),
2 => Some(Self::Random),
3 => Some(Self::RandomPositive),
4 => Some(Self::RandomNegative),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for DayEntryRandomizationTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for DayEntryRandomizationTypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum DayTypeEnum {
Standard = 0,
Holiday = 1,
Dynamic = 2,
Event = 3,
}
impl DayTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Standard),
1 => Some(Self::Holiday),
2 => Some(Self::Dynamic),
3 => Some(Self::Event),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for DayTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for DayTypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum PeakPeriodSeverityEnum {
Unused = 0,
Low = 1,
Medium = 2,
High = 3,
}
impl PeakPeriodSeverityEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Unused),
1 => Some(Self::Low),
2 => Some(Self::Medium),
3 => Some(Self::High),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for PeakPeriodSeverityEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for PeakPeriodSeverityEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct DayPatternDayOfWeekBitmap: u8 {
const SUNDAY = 1 << 0;
const MONDAY = 1 << 1;
const TUESDAY = 1 << 2;
const WEDNESDAY = 1 << 3;
const THURSDAY = 1 << 4;
const FRIDAY = 1 << 5;
const SATURDAY = 1 << 6;
}
}
impl ToTlv for DayPatternDayOfWeekBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for DayPatternDayOfWeekBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AuxiliaryLoadSwitchSettingsStruct {
pub number: u8,
pub required_state: AuxiliaryLoadSettingEnum,
}
impl ToTlv for AuxiliaryLoadSwitchSettingsStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.number.to_tlv(w, Tag::Context(0))?;
self.required_state.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AuxiliaryLoadSwitchSettingsStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut number = None;
let mut required_state = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => number = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => {
required_state = Some(<AuxiliaryLoadSettingEnum>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
number: number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
required_state: required_state
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AuxiliaryLoadSwitchesSettingsStruct<'a> {
pub switch_states: TlvList<'a, AuxiliaryLoadSwitchSettingsStruct>,
}
impl<'a> ToTlv for AuxiliaryLoadSwitchesSettingsStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.switch_states.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AuxiliaryLoadSwitchesSettingsStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut switch_states = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
switch_states = Some(
<TlvList<'a, AuxiliaryLoadSwitchSettingsStruct>>::from_tlv(reader, &field)?,
)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
switch_states: switch_states.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CalendarPeriodStruct<'a> {
pub start_date: Nullable<u32>,
pub day_pattern_i_ds: TlvList<'a, u32>,
}
impl<'a> ToTlv for CalendarPeriodStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.start_date.to_tlv(w, Tag::Context(0))?;
self.day_pattern_i_ds.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for CalendarPeriodStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut start_date = None;
let mut day_pattern_i_ds = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => start_date = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
Some(1) => day_pattern_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
start_date: start_date.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_pattern_i_ds: day_pattern_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DayEntryStruct {
pub day_entry_id: u32,
pub start_time: u16,
pub duration: Option<u16>,
pub randomization_offset: Option<i16>,
pub randomization_type: Option<DayEntryRandomizationTypeEnum>,
}
impl ToTlv for DayEntryStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.day_entry_id.to_tlv(w, Tag::Context(0))?;
self.start_time.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.duration {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.randomization_offset {
value.to_tlv(w, Tag::Context(3))?;
}
if let Some(value) = &self.randomization_type {
value.to_tlv(w, Tag::Context(4))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for DayEntryStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut day_entry_id = None;
let mut start_time = None;
let mut duration = None;
let mut randomization_offset = None;
let mut randomization_type = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => day_entry_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => start_time = Some(<u16>::from_tlv(reader, &field)?),
Some(2) => duration = Some(<u16>::from_tlv(reader, &field)?),
Some(3) => randomization_offset = Some(<i16>::from_tlv(reader, &field)?),
Some(4) => {
randomization_type =
Some(<DayEntryRandomizationTypeEnum>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
day_entry_id: day_entry_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
start_time: start_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
duration,
randomization_offset,
randomization_type,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DayPatternStruct<'a> {
pub day_pattern_id: u32,
pub days_of_week: DayPatternDayOfWeekBitmap,
pub day_entry_i_ds: TlvList<'a, u32>,
}
impl<'a> ToTlv for DayPatternStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.day_pattern_id.to_tlv(w, Tag::Context(0))?;
self.days_of_week.to_tlv(w, Tag::Context(1))?;
self.day_entry_i_ds.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for DayPatternStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut day_pattern_id = None;
let mut days_of_week = None;
let mut day_entry_i_ds = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => day_pattern_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => {
days_of_week = Some(<DayPatternDayOfWeekBitmap>::from_tlv(reader, &field)?)
}
Some(2) => day_entry_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
day_pattern_id: day_pattern_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
days_of_week: days_of_week.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_entry_i_ds: day_entry_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DayStruct<'a> {
pub date: u32,
pub day_type: DayTypeEnum,
pub day_entry_i_ds: TlvList<'a, u32>,
}
impl<'a> ToTlv for DayStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.date.to_tlv(w, Tag::Context(0))?;
self.day_type.to_tlv(w, Tag::Context(1))?;
self.day_entry_i_ds.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for DayStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut date = None;
let mut day_type = None;
let mut day_entry_i_ds = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => date = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => day_type = Some(<DayTypeEnum>::from_tlv(reader, &field)?),
Some(2) => day_entry_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
date: date.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_type: day_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_entry_i_ds: day_entry_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PeakPeriodStruct {
pub severity: PeakPeriodSeverityEnum,
pub peak_period: u16,
}
impl ToTlv for PeakPeriodStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.severity.to_tlv(w, Tag::Context(0))?;
self.peak_period.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for PeakPeriodStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut severity = None;
let mut peak_period = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => severity = Some(<PeakPeriodSeverityEnum>::from_tlv(reader, &field)?),
Some(1) => peak_period = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
severity: severity.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
peak_period: peak_period.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TariffComponentStruct<'a> {
pub tariff_component_id: u32,
pub price: Option<Nullable<TariffPriceStruct>>,
pub friendly_credit: Option<bool>,
pub auxiliary_load: Option<AuxiliaryLoadSwitchSettingsStruct>,
pub peak_period: Option<PeakPeriodStruct>,
pub power_threshold: Option<crate::clusters::generated::globals::PowerThresholdStruct>,
pub threshold: Nullable<i64>,
pub label: Option<Nullable<&'a str>>,
pub predicted: Option<bool>,
}
impl<'a> ToTlv for TariffComponentStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.tariff_component_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.price {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.friendly_credit {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.auxiliary_load {
value.to_tlv(w, Tag::Context(3))?;
}
if let Some(value) = &self.peak_period {
value.to_tlv(w, Tag::Context(4))?;
}
if let Some(value) = &self.power_threshold {
value.to_tlv(w, Tag::Context(5))?;
}
self.threshold.to_tlv(w, Tag::Context(6))?;
if let Some(value) = &self.label {
value.to_tlv(w, Tag::Context(7))?;
}
if let Some(value) = &self.predicted {
value.to_tlv(w, Tag::Context(8))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for TariffComponentStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut tariff_component_id = None;
let mut price = None;
let mut friendly_credit = None;
let mut auxiliary_load = None;
let mut peak_period = None;
let mut power_threshold = None;
let mut threshold = None;
let mut label = None;
let mut predicted = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => tariff_component_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => price = Some(<Nullable<TariffPriceStruct>>::from_tlv(reader, &field)?),
Some(2) => friendly_credit = Some(<bool>::from_tlv(reader, &field)?),
Some(3) => {
auxiliary_load = Some(<AuxiliaryLoadSwitchSettingsStruct>::from_tlv(
reader, &field,
)?)
}
Some(4) => peak_period = Some(<PeakPeriodStruct>::from_tlv(reader, &field)?),
Some(5) => {
power_threshold = Some(
<crate::clusters::generated::globals::PowerThresholdStruct>::from_tlv(
reader, &field,
)?,
)
}
Some(6) => threshold = Some(<Nullable<i64>>::from_tlv(reader, &field)?),
Some(7) => label = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
Some(8) => predicted = Some(<bool>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
tariff_component_id: tariff_component_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
price,
friendly_credit,
auxiliary_load,
peak_period,
power_threshold,
threshold: threshold.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
label,
predicted,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TariffInformationStruct<'a> {
pub tariff_label: Nullable<&'a str>,
pub provider_name: Nullable<&'a str>,
pub currency: Option<Nullable<crate::clusters::generated::globals::CurrencyStruct>>,
pub block_mode: Nullable<BlockModeEnum>,
}
impl<'a> ToTlv for TariffInformationStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.tariff_label.to_tlv(w, Tag::Context(0))?;
self.provider_name.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.currency {
value.to_tlv(w, Tag::Context(2))?;
}
self.block_mode.to_tlv(w, Tag::Context(3))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TariffInformationStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut tariff_label = None;
let mut provider_name = None;
let mut currency = None;
let mut block_mode = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => tariff_label = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
Some(1) => provider_name = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
Some(2) => {
currency = Some(<Nullable<
crate::clusters::generated::globals::CurrencyStruct,
>>::from_tlv(reader, &field)?)
}
Some(3) => block_mode = Some(<Nullable<BlockModeEnum>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
tariff_label: tariff_label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
provider_name: provider_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
currency,
block_mode: block_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TariffPeriodStruct<'a> {
pub label: Nullable<&'a str>,
pub day_entry_i_ds: TlvList<'a, u32>,
pub tariff_component_i_ds: TlvList<'a, u32>,
}
impl<'a> ToTlv for TariffPeriodStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.label.to_tlv(w, Tag::Context(0))?;
self.day_entry_i_ds.to_tlv(w, Tag::Context(1))?;
self.tariff_component_i_ds.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for TariffPeriodStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut label = None;
let mut day_entry_i_ds = None;
let mut tariff_component_i_ds = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => label = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
Some(1) => day_entry_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
Some(2) => {
tariff_component_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_entry_i_ds: day_entry_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
tariff_component_i_ds: tariff_component_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TariffPriceStruct {
pub price_type: crate::clusters::generated::globals::TariffPriceTypeEnum,
pub price: Option<i64>,
pub price_level: Option<i16>,
}
impl ToTlv for TariffPriceStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.price_type.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.price {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.price_level {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for TariffPriceStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut price_type = None;
let mut price = None;
let mut price_level = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
price_type = Some(
<crate::clusters::generated::globals::TariffPriceTypeEnum>::from_tlv(
reader, &field,
)?,
)
}
Some(1) => price = Some(<i64>::from_tlv(reader, &field)?),
Some(2) => price_level = Some(<i16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
price_type: price_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
price,
price_level,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetTariffComponentFields {
pub tariff_component_id: u32,
}
impl ToTlv for GetTariffComponentFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.tariff_component_id.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetTariffComponentFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut tariff_component_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => tariff_component_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
tariff_component_id: tariff_component_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetTariffComponentResponseFields<'a> {
pub label: Nullable<&'a str>,
pub day_entry_i_ds: TlvList<'a, u32>,
pub tariff_component: TariffComponentStruct<'a>,
}
impl<'a> ToTlv for GetTariffComponentResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.label.to_tlv(w, Tag::Context(0))?;
self.day_entry_i_ds.to_tlv(w, Tag::Context(1))?;
self.tariff_component.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetTariffComponentResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut label = None;
let mut day_entry_i_ds = None;
let mut tariff_component = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => label = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
Some(1) => day_entry_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
Some(2) => {
tariff_component = Some(<TariffComponentStruct<'a>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
day_entry_i_ds: day_entry_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
tariff_component: tariff_component
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetDayEntryFields {
pub day_entry_id: u32,
}
impl ToTlv for GetDayEntryFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.day_entry_id.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetDayEntryFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut day_entry_id = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => day_entry_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
day_entry_id: day_entry_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GetDayEntryResponseFields {
pub day_entry: DayEntryStruct,
}
impl ToTlv for GetDayEntryResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.day_entry.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GetDayEntryResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut day_entry = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => day_entry = Some(<DayEntryStruct>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
day_entry: day_entry.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "TariffInfo",
kind: "TariffInformationStruct",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "TariffUnit",
kind: "TariffUnitEnum",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0002,
name: "StartDate",
kind: "epoch-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0003,
name: "DayEntries",
kind: "list[DayEntryStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0004,
name: "DayPatterns",
kind: "list[DayPatternStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0005,
name: "CalendarPeriods",
kind: "list[CalendarPeriodStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0006,
name: "IndividualDays",
kind: "list[DayStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0007,
name: "CurrentDay",
kind: "DayStruct",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0008,
name: "NextDay",
kind: "DayStruct",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0009,
name: "CurrentDayEntry",
kind: "DayEntryStruct",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000A,
name: "CurrentDayEntryDate",
kind: "epoch-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000B,
name: "NextDayEntry",
kind: "DayEntryStruct",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000C,
name: "NextDayEntryDate",
kind: "epoch-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000D,
name: "TariffComponents",
kind: "list[TariffComponentStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000E,
name: "TariffPeriods",
kind: "list[TariffPeriodStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000F,
name: "CurrentTariffComponents",
kind: "list[TariffComponentStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0010,
name: "NextTariffComponents",
kind: "list[TariffComponentStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0011,
name: "DefaultRandomizationOffset",
kind: "int16",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(5),
}],
},
},
Attribute {
id: 0x0012,
name: "DefaultRandomizationType",
kind: "DayEntryRandomizationTypeEnum",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(5),
}],
},
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "GetTariffComponent",
to_server: true,
response: Some(0x00),
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x00,
name: "GetTariffComponentResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "GetDayEntry",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "GetDayEntryResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Commodity Tariff",
revision: REVISION,
pics: "SETRF",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};