Comments (7)
I don't see why not, but unfortunately, I don't have a P115 to test with.
Can you please try and use it through the P110
interface and see how that goes?
from tapo.
I tried cargo run --example tapo_p110
but I get: Couldn't connect to server
from tapo.
It's actually working. I haven't written a byte in Rust until now, can you help with serializing tapo_date_format to JSON?
from tapo.
I found a way using, not sure if it's the best.
pub fn serialize<S>(
date: &OffsetDateTime,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
// let format = format_description::parse(
// "[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour \
// sign:mandatory]:[offset_minute]:[offset_second]",
// )?;
let s = format!("{}", date);
serializer.serialize_str(&s)
}
from tapo.
What are you trying to achieve that requires you to serialize a date?
If you're trying to send the tapo responses to another API, which requires serialization, you will probably be better off with building your own structs that #[derive(serde::Serialize)]
and map the tapo response into them.
from tapo.
I'd like to save them as JSON to docker stdout log, and pick them up with Logstash.
Mapping in Rust is done using From trait? Or is there an automapper lib like in C#?
from tapo.
Probably there are some mappers, but they might be overkill for your use case.
You're correct, the From
trait would get the job done quite easily.
#[derive(Debug, serde::Serialize)]
pub struct EnergyData {
pub local_time: time::OffsetDateTime,
pub data: Vec<u64>,
pub start_timestamp: u64,
pub end_timestamp: u64,
pub interval: u64,
}
impl From<EnergyDataResult> for EnergyData {
fn from(energy_data: EnergyDataResult) -> Self {
Self {
local_time: energy_data.local_time,
data: energy_data.data,
start_timestamp: energy_data.start_timestamp,
end_timestamp: energy_data.end_timestamp,
interval: energy_data.interval,
}
}
}
Then you can use it like this:
let energy_data: EnergyData = energy_data_monthly.into();
let _json = serde_json::to_string_pretty(&energy_data)?;
One gotcha is that you have to bring in the time
crate with the serde
feature so that you can serialize time::OffsetDateTime
automatically.
time = { version = "0.3", features = ["serde"] }
from tapo.
Related Issues (20)
- Tapo API Client with HA HOT 3
- P110 getting current energy usage via different api method HOT 9
- Error: Tapo(InvalidCredentials) HOT 2
- Unkown error 1003 when trying to login to device HOT 21
- How to actually use this? HOT 2
- Question: Tapo P115 Energy Data HOT 14
- Support for KE100 (TRV) via H100 HOT 5
- Can't compile `curl-sys v0.4.68+curl-8.4.0` on M1 Pro with Sonoma HOT 2
- Python support/examples for L530 please HOT 5
- Energy data interval HOT 1
- H100 Support in Python HOT 2
- basic guide of usage under windows? HOT 2
- Docker image and rest api HOT 20
- on_time characteristic causing error HOT 3
- P110 `get_energy_usage` errors on the latest firmware HOT 1
- Feature request: toggle state HOT 4
- Build error HOT 4
- Using as logstash producer HOT 1
- HELP request on code, not execution issue. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tapo.