forked from platypush/platypush
[weather.buienradar] Implemented forecast support.
This commit is contained in:
parent
b969afb1cf
commit
71ccffa698
4 changed files with 23 additions and 13 deletions
|
@ -6,7 +6,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-5 name">
|
<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 class="name" v-text="value.name" v-else />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -170,12 +172,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import EntityIcon from "./EntityIcon"
|
|
||||||
import EntityMixin from "./EntityMixin"
|
import EntityMixin from "./EntityMixin"
|
||||||
import WeatherIcon from "./WeatherIcon"
|
import WeatherIcon from "./WeatherIcon"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {EntityIcon, WeatherIcon},
|
components: {WeatherIcon},
|
||||||
mixins: [EntityMixin],
|
mixins: [EntityMixin],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -16,10 +16,13 @@ export default {
|
||||||
return date.toTimeString().substring(0, seconds ? 8 : 5)
|
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')
|
if (typeof date === 'string')
|
||||||
date = new Date(Date.parse(date))
|
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)}`
|
return `${this.formatDate(date, year)}, ${this.formatTime(date, seconds)}`
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,17 +61,12 @@ class WeatherBuienradarPlugin(WeatherPlugin): # pylint: disable=too-many-ancest
|
||||||
"""
|
"""
|
||||||
return WeatherSchema().dump(self.get_data(lat, long, 60))
|
return WeatherSchema().dump(self.get_data(lat, long, 60))
|
||||||
|
|
||||||
@action
|
def _get_forecast(
|
||||||
def get_forecast(self, lat: Optional[float] = None, long: Optional[float] = None):
|
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)
|
|
||||||
"""
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'datetime': weather.get('datetime'),
|
'datetime': weather['datetime'].isoformat(),
|
||||||
**dict(WeatherSchema().dump(weather)),
|
**dict(WeatherSchema().dump(weather)),
|
||||||
}
|
}
|
||||||
for weather in self.get_data(lat, long, 60).get('forecast', [])
|
for weather in self.get_data(lat, long, 60).get('forecast', [])
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from marshmallow import EXCLUDE, fields
|
from marshmallow import EXCLUDE, fields
|
||||||
from marshmallow.schema import Schema
|
from marshmallow.schema import Schema
|
||||||
|
|
||||||
|
from platypush.schemas import DateTime
|
||||||
|
|
||||||
|
|
||||||
class WeatherSchema(Schema):
|
class WeatherSchema(Schema):
|
||||||
"""
|
"""
|
||||||
|
@ -14,6 +16,15 @@ class WeatherSchema(Schema):
|
||||||
|
|
||||||
unknown = EXCLUDE
|
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(
|
summary = fields.Function(
|
||||||
lambda obj: obj.get('condition', {}).get('exact', 'Unknown'),
|
lambda obj: obj.get('condition', {}).get('exact', 'Unknown'),
|
||||||
metadata={
|
metadata={
|
||||||
|
|
Loading…
Reference in a new issue