Skip to content

Commit

Permalink
fix for year string
Browse files Browse the repository at this point in the history
  • Loading branch information
sanghviharshit committed May 4, 2022
1 parent 80c0c8a commit 6b370fd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custom_components/meural/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
vol.Optional("author"): str,
vol.Optional("description"): str,
vol.Optional("medium"): str,
vol.Optional("year"): int,
vol.Optional("year"): str,
},
"async_preview_image_cloud",
)
Expand Down
16 changes: 5 additions & 11 deletions custom_components/meural/pymeural.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
import json
from datetime import datetime
from datetime import date

from typing import Dict
import aiohttp
Expand Down Expand Up @@ -139,14 +139,12 @@ async def get_item(self, item_id):
async def update_content(self, id, name=None, author=None, description=None, medium=None, year=None):
_LOGGER.info(f"Meural: Updating postcard. Id is {id}")

now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")

name = "Homeassistant Preview Image" if name == None else name
author = "Homeassistant" if author == None else author
description = "Preview Image from Home Assistant Meural component" if description == None else description
medium = "Photo" if medium == None else medium
year = dt_string if year == None else str(year)
# the year has to be a date. other format doesn't work
year = date.today() if year == None else str(year)

data = aiohttp.FormData()
data.add_field("name", name)
Expand Down Expand Up @@ -176,17 +174,13 @@ async def upload_content(self, url, content_type, name):

data = aiohttp.FormData()

field_name = 'image'
if not (content_type == 'image/jpg' or content_type == 'image/jpeg'):
field_name = 'video'
data.add_field(field_name, content, filename=name,
data.add_field('image', content, filename=name,
content_type=content_type)

response = await self.request("post", f"items",
data=data, data_key="data")

_LOGGER.info('Meural: Sending postcard. %s uploaded' % (
field_name))
_LOGGER.info('Meural: Sending postcard. Image uploaded')
return response

async def preview_item(self, device_id, item_id):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/meural/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ preview_image_cloud:
description: Medium for the media item
example: Photography
year:
description: Year
description: Year. This needs to be a date or just the year. Other format doesn't work
example: 2022/05/01

set_device_option:
Expand Down

0 comments on commit 6b370fd

Please sign in to comment.