diff options
Diffstat (limited to 'src/entity_number.rs')
| -rw-r--r-- | src/entity_number.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/entity_number.rs b/src/entity_number.rs index f96c3c7..e2a89c1 100644 --- a/src/entity_number.rs +++ b/src/entity_number.rs | |||
| @@ -70,6 +70,7 @@ pub struct NumberConfig { | |||
| 70 | pub step: Option<f32>, | 70 | pub step: Option<f32>, |
| 71 | pub mode: NumberMode, | 71 | pub mode: NumberMode, |
| 72 | pub class: NumberClass, | 72 | pub class: NumberClass, |
| 73 | pub publish_on_command: bool, | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | impl Default for NumberConfig { | 76 | impl Default for NumberConfig { |
| @@ -82,6 +83,7 @@ impl Default for NumberConfig { | |||
| 82 | step: None, | 83 | step: None, |
| 83 | mode: NumberMode::Auto, | 84 | mode: NumberMode::Auto, |
| 84 | class: NumberClass::Generic, | 85 | class: NumberClass::Generic, |
| 86 | publish_on_command: true, | ||
| 85 | } | 87 | } |
| 86 | } | 88 | } |
| 87 | } | 89 | } |
| @@ -169,24 +171,31 @@ impl<'a> Number<'a> { | |||
| 169 | Self(entity) | 171 | Self(entity) |
| 170 | } | 172 | } |
| 171 | 173 | ||
| 172 | pub fn get(&mut self) -> Option<f32> { | 174 | pub fn state(&mut self) -> Option<f32> { |
| 173 | self.0.with_data(|data| { | 175 | self.0.with_data(|data| { |
| 174 | let storage = data.storage.as_number_mut(); | 176 | let storage = data.storage.as_number_mut(); |
| 175 | storage.state.as_ref().map(|s| s.value) | 177 | storage.state.as_ref().map(|s| s.value) |
| 176 | }) | 178 | }) |
| 177 | } | 179 | } |
| 178 | 180 | ||
| 181 | pub fn command(&self) -> Option<f32> { | ||
| 182 | self.0.with_data(|data| { | ||
| 183 | let storage = data.storage.as_number_mut(); | ||
| 184 | storage.command.as_ref().map(|s| s.value) | ||
| 185 | }) | ||
| 186 | } | ||
| 187 | |||
| 179 | pub async fn wait(&mut self) -> f32 { | 188 | pub async fn wait(&mut self) -> f32 { |
| 180 | loop { | 189 | loop { |
| 181 | self.0.wait_command().await; | 190 | self.0.wait_command().await; |
| 182 | match self.get() { | 191 | match self.command() { |
| 183 | Some(value) => return value, | 192 | Some(value) => return value, |
| 184 | None => continue, | 193 | None => continue, |
| 185 | } | 194 | } |
| 186 | } | 195 | } |
| 187 | } | 196 | } |
| 188 | 197 | ||
| 189 | pub fn set(&mut self, value: f32) { | 198 | pub fn publish(&mut self, value: f32) { |
| 190 | let publish = self.0.with_data(|data| { | 199 | let publish = self.0.with_data(|data| { |
| 191 | let storage = data.storage.as_number_mut(); | 200 | let storage = data.storage.as_number_mut(); |
| 192 | let timestamp = embassy_time::Instant::now(); | 201 | let timestamp = embassy_time::Instant::now(); |
