mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Dominos no order fix (#10935)
* check for none * fix error from no store being set * typo * Lint * fix default as per notes. Lint fix and make closest store None not False * update default
This commit is contained in:
parent
29fad3fa3c
commit
bd6a17a3a5
@ -58,7 +58,8 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
vol.Required(ATTR_PHONE): cv.string,
|
vol.Required(ATTR_PHONE): cv.string,
|
||||||
vol.Required(ATTR_ADDRESS): cv.string,
|
vol.Required(ATTR_ADDRESS): cv.string,
|
||||||
vol.Optional(ATTR_SHOW_MENU): cv.boolean,
|
vol.Optional(ATTR_SHOW_MENU): cv.boolean,
|
||||||
vol.Optional(ATTR_ORDERS): vol.All(cv.ensure_list, [_ORDERS_SCHEMA]),
|
vol.Optional(ATTR_ORDERS, default=[]): vol.All(
|
||||||
|
cv.ensure_list, [_ORDERS_SCHEMA]),
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
@ -81,7 +82,8 @@ def setup(hass, config):
|
|||||||
order = DominosOrder(order_info, dominos)
|
order = DominosOrder(order_info, dominos)
|
||||||
entities.append(order)
|
entities.append(order)
|
||||||
|
|
||||||
component.add_entities(entities)
|
if entities:
|
||||||
|
component.add_entities(entities)
|
||||||
|
|
||||||
# Return boolean to indicate that initialization was successfully.
|
# Return boolean to indicate that initialization was successfully.
|
||||||
return True
|
return True
|
||||||
@ -93,7 +95,8 @@ class Dominos():
|
|||||||
def __init__(self, hass, config):
|
def __init__(self, hass, config):
|
||||||
"""Set up main service."""
|
"""Set up main service."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
from pizzapi import Address, Customer, Store
|
from pizzapi import Address, Customer
|
||||||
|
from pizzapi.address import StoreException
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.customer = Customer(
|
self.customer = Customer(
|
||||||
conf.get(ATTR_FIRST_NAME),
|
conf.get(ATTR_FIRST_NAME),
|
||||||
@ -105,7 +108,10 @@ class Dominos():
|
|||||||
*self.customer.address.split(','),
|
*self.customer.address.split(','),
|
||||||
country=conf.get(ATTR_COUNTRY))
|
country=conf.get(ATTR_COUNTRY))
|
||||||
self.country = conf.get(ATTR_COUNTRY)
|
self.country = conf.get(ATTR_COUNTRY)
|
||||||
self.closest_store = Store()
|
try:
|
||||||
|
self.closest_store = self.address.closest_store()
|
||||||
|
except StoreException:
|
||||||
|
self.closest_store = None
|
||||||
|
|
||||||
def handle_order(self, call):
|
def handle_order(self, call):
|
||||||
"""Handle ordering pizza."""
|
"""Handle ordering pizza."""
|
||||||
@ -123,29 +129,31 @@ class Dominos():
|
|||||||
from pizzapi.address import StoreException
|
from pizzapi.address import StoreException
|
||||||
try:
|
try:
|
||||||
self.closest_store = self.address.closest_store()
|
self.closest_store = self.address.closest_store()
|
||||||
|
return True
|
||||||
except StoreException:
|
except StoreException:
|
||||||
self.closest_store = False
|
self.closest_store = None
|
||||||
|
return False
|
||||||
|
|
||||||
def get_menu(self):
|
def get_menu(self):
|
||||||
"""Return the products from the closest stores menu."""
|
"""Return the products from the closest stores menu."""
|
||||||
if self.closest_store is False:
|
if self.closest_store is None:
|
||||||
_LOGGER.warning('Cannot get menu. Store may be closed')
|
_LOGGER.warning('Cannot get menu. Store may be closed')
|
||||||
return
|
return []
|
||||||
|
else:
|
||||||
|
menu = self.closest_store.get_menu()
|
||||||
|
product_entries = []
|
||||||
|
|
||||||
menu = self.closest_store.get_menu()
|
for product in menu.products:
|
||||||
product_entries = []
|
item = {}
|
||||||
|
if isinstance(product.menu_data['Variants'], list):
|
||||||
|
variants = ', '.join(product.menu_data['Variants'])
|
||||||
|
else:
|
||||||
|
variants = product.menu_data['Variants']
|
||||||
|
item['name'] = product.name
|
||||||
|
item['variants'] = variants
|
||||||
|
product_entries.append(item)
|
||||||
|
|
||||||
for product in menu.products:
|
return product_entries
|
||||||
item = {}
|
|
||||||
if isinstance(product.menu_data['Variants'], list):
|
|
||||||
variants = ', '.join(product.menu_data['Variants'])
|
|
||||||
else:
|
|
||||||
variants = product.menu_data['Variants']
|
|
||||||
item['name'] = product.name
|
|
||||||
item['variants'] = variants
|
|
||||||
product_entries.append(item)
|
|
||||||
|
|
||||||
return product_entries
|
|
||||||
|
|
||||||
|
|
||||||
class DominosProductListView(http.HomeAssistantView):
|
class DominosProductListView(http.HomeAssistantView):
|
||||||
@ -192,7 +200,7 @@ class DominosOrder(Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state either closed, orderable or unorderable."""
|
"""Return the state either closed, orderable or unorderable."""
|
||||||
if self.dominos.closest_store is False:
|
if self.dominos.closest_store is None:
|
||||||
return 'closed'
|
return 'closed'
|
||||||
else:
|
else:
|
||||||
return 'orderable' if self._orderable else 'unorderable'
|
return 'orderable' if self._orderable else 'unorderable'
|
||||||
@ -217,6 +225,11 @@ class DominosOrder(Entity):
|
|||||||
def order(self):
|
def order(self):
|
||||||
"""Create the order object."""
|
"""Create the order object."""
|
||||||
from pizzapi import Order
|
from pizzapi import Order
|
||||||
|
from pizzapi.address import StoreException
|
||||||
|
|
||||||
|
if self.dominos.closest_store is None:
|
||||||
|
raise StoreException
|
||||||
|
|
||||||
order = Order(
|
order = Order(
|
||||||
self.dominos.closest_store,
|
self.dominos.closest_store,
|
||||||
self.dominos.customer,
|
self.dominos.customer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user