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:
Craig J. Ward 2017-12-03 21:34:58 -06:00 committed by Paulus Schoutsen
parent 29fad3fa3c
commit bd6a17a3a5

View File

@ -58,7 +58,8 @@ CONFIG_SCHEMA = vol.Schema({
vol.Required(ATTR_PHONE): cv.string,
vol.Required(ATTR_ADDRESS): cv.string,
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)
@ -81,6 +82,7 @@ def setup(hass, config):
order = DominosOrder(order_info, dominos)
entities.append(order)
if entities:
component.add_entities(entities)
# Return boolean to indicate that initialization was successfully.
@ -93,7 +95,8 @@ class Dominos():
def __init__(self, hass, config):
"""Set up main service."""
conf = config[DOMAIN]
from pizzapi import Address, Customer, Store
from pizzapi import Address, Customer
from pizzapi.address import StoreException
self.hass = hass
self.customer = Customer(
conf.get(ATTR_FIRST_NAME),
@ -105,7 +108,10 @@ class Dominos():
*self.customer.address.split(','),
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):
"""Handle ordering pizza."""
@ -123,15 +129,17 @@ class Dominos():
from pizzapi.address import StoreException
try:
self.closest_store = self.address.closest_store()
return True
except StoreException:
self.closest_store = False
self.closest_store = None
return False
def get_menu(self):
"""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')
return
return []
else:
menu = self.closest_store.get_menu()
product_entries = []
@ -192,7 +200,7 @@ class DominosOrder(Entity):
@property
def state(self):
"""Return the state either closed, orderable or unorderable."""
if self.dominos.closest_store is False:
if self.dominos.closest_store is None:
return 'closed'
else:
return 'orderable' if self._orderable else 'unorderable'
@ -217,6 +225,11 @@ class DominosOrder(Entity):
def order(self):
"""Create the order object."""
from pizzapi import Order
from pizzapi.address import StoreException
if self.dominos.closest_store is None:
raise StoreException
order = Order(
self.dominos.closest_store,
self.dominos.customer,