[weather.buienradar] Implemented forecast support.

This commit is contained in:
Fabio Manganiello 2023-11-23 01:35:25 +01:00
parent b969afb1cf
commit 71ccffa698
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 23 additions and 13 deletions

View file

@ -6,7 +6,9 @@
</div>
<div class="col-5 name">
<div class="name" v-text="formatDateTime(value.time, year=false, seconds=false)" v-if="isForecast" />
<div class="name"
v-text="formatDateTime(value.time, year=false, seconds=false, skipTimeIfMidnight=true)"
v-if="isForecast" />
<div class="name" v-text="value.name" v-else />
</div>
@ -170,12 +172,11 @@
</template>
<script>
import EntityIcon from "./EntityIcon"
import EntityMixin from "./EntityMixin"
import WeatherIcon from "./WeatherIcon"
export default {
components: {EntityIcon, WeatherIcon},
components: {WeatherIcon},
mixins: [EntityMixin],
props: {

View file

@ -16,10 +16,13 @@ export default {
return date.toTimeString().substring(0, seconds ? 8 : 5)
},
formatDateTime(date, year=false, seconds=true) {
formatDateTime(date, year=false, seconds=true, skipTimeIfMidnight=false) {
if (typeof date === 'string')
date = new Date(Date.parse(date))
if (skipTimeIfMidnight && date.getHours() === 0 && date.getMinutes() === 0 && date.getSeconds() === 0)
return this.formatDate(date, year)
return `${this.formatDate(date, year)}, ${this.formatTime(date, seconds)}`
},
},

View file

@ -61,17 +61,12 @@ class WeatherBuienradarPlugin(WeatherPlugin): # pylint: disable=too-many-ancest
"""
return WeatherSchema().dump(self.get_data(lat, long, 60))
@action
def get_forecast(self, lat: Optional[float] = None, long: Optional[float] = None):
"""
Get the weather forecast for the next days.
:param lat: Weather latitude (default: configured latitude)
:param long: Weather longitude (default: configured longitude)
"""
def _get_forecast(
self, *_, lat: Optional[float] = None, long: Optional[float] = None, **__
):
return [
{
'datetime': weather.get('datetime'),
'datetime': weather['datetime'].isoformat(),
**dict(WeatherSchema().dump(weather)),
}
for weather in self.get_data(lat, long, 60).get('forecast', [])

View file

@ -1,6 +1,8 @@
from marshmallow import EXCLUDE, fields
from marshmallow.schema import Schema
from platypush.schemas import DateTime
class WeatherSchema(Schema):
"""
@ -14,6 +16,15 @@ class WeatherSchema(Schema):
unknown = EXCLUDE
time = DateTime(
required=True,
attribute='datetime',
metadata={
'description': 'Date and time of the weather data',
'example': '2020-01-01T00:00:00+00:00',
},
)
summary = fields.Function(
lambda obj: obj.get('condition', {}).get('exact', 'Unknown'),
metadata={