Skip to content

Commit

Permalink
feat: add type hints and update poster default
Browse files Browse the repository at this point in the history
  • Loading branch information
hudsonbrendon committed Sep 13, 2022
1 parent 49bc211 commit 127bbb1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion custom_components/ingresso/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BASE_URL = "https://api-content.ingresso.com/v0/templates/nowplaying/{}?partnership={}"
DEFAULT_POSTER = "https://www.promoview.com.br/uploads/2019/01/images/07.01.2019/ingresso.comlogo.jpg"
ICON = "mdi:ticket"

CONF_CITY_ID = "city_id"
CONF_CITY_NAME = "city_name"
CONF_PARTNERSHIP = "partnership"
DEFAULT_POSTER = "https://www.youtube.com/user/ingressocom"
5 changes: 3 additions & 2 deletions custom_components/ingresso/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"domain": "ingresso",
"name": "Ingresso",
"version": "2.3.9",
"version": "2.6.1",
"documentation": "https://github.com/hudsonbrendon/sensor.ingresso.com",
"dependencies": [],
"codeowners": ["@hudsonbrendon"],
"requirements": []
"requirements": [],
"iot_class": "cloud_polling"
}
32 changes: 21 additions & 11 deletions custom_components/ingresso/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
https://github.com/hudsonbrendon/sensor.ingresso.com
"""
import logging
from typing import List

import homeassistant.helpers.config_validation as cv
import requests
import voluptuous as vol
from aiohttp import ClientSession
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.helpers.entity import Entity
Expand All @@ -35,7 +37,7 @@
_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None) -> None:
"""Setup sensor platform."""
city_id = config["city_id"]
city_name = config["city_name"]
Expand All @@ -48,7 +50,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class IngressoSensor(Entity):
"""Ingresso.com Sensor class"""

def __init__(self, city_id, city_name, partnership, name, session):
def __init__(self, city_id: int, city_name: str, partnership: str, name: str, session: ClientSession) -> None:
self._state = city_name
self._city_id = city_id
self._partnership = partnership
Expand All @@ -57,36 +59,44 @@ def __init__(self, city_id, city_name, partnership, name, session):
self._movies = []

@property
def name(self):
def city_id(self) -> int:
return self._city_id

@property
def partnership(self) -> str:
return self._partnership

@property
def name(self) -> str:
"""Name."""
return self._name

@property
def state(self):
def state(self) -> str:
"""State."""
return self._state
return len(self.movies)

@property
def movies(self):
def movies(self) -> List[dict]:
"""Movies."""
return self._movies

@property
def icon(self):
def icon(self) -> str:
"""Icon."""
return ICON

@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict:
"""Attributes."""
return {
"data": self.movies,
}

def update(self):
def update(self) -> None:
"""Update sensor."""
_LOGGER.debug("%s - Running update", self._name)
url = BASE_URL.format(self._city_id, self._partnership)
_LOGGER.debug("%s - Running update", self.name)
url = BASE_URL.format(self.city_id, self.partnership)

retry_strategy = Retry(total=3, status_forcelist=[400, 401, 404, 500, 502, 503, 504], method_whitelist=["GET"])
adapter = HTTPAdapter(max_retries=retry_strategy)
Expand Down

0 comments on commit 127bbb1

Please sign in to comment.