1 """Support for Dominos Pizza ordering."""
3 from datetime
import timedelta
6 from pizzapi
import Address, Customer, Order
7 import voluptuous
as vol
18 _LOGGER = logging.getLogger(__name__)
22 ENTITY_ID_FORMAT = DOMAIN +
".{}"
24 ATTR_COUNTRY =
"country_code"
25 ATTR_FIRST_NAME =
"first_name"
26 ATTR_LAST_NAME =
"last_name"
29 ATTR_ADDRESS =
"address"
30 ATTR_ORDERS =
"orders"
31 ATTR_SHOW_MENU =
"show_menu"
32 ATTR_ORDER_ENTITY =
"order_entity_id"
33 ATTR_ORDER_NAME =
"name"
34 ATTR_ORDER_CODES =
"codes"
37 MIN_TIME_BETWEEN_STORE_UPDATES =
timedelta(minutes=3330)
39 _ORDERS_SCHEMA = vol.Schema(
41 vol.Required(ATTR_ORDER_NAME): cv.string,
42 vol.Required(ATTR_ORDER_CODES): vol.All(cv.ensure_list, [cv.string]),
46 CONFIG_SCHEMA = vol.Schema(
50 vol.Required(ATTR_COUNTRY): cv.string,
51 vol.Required(ATTR_FIRST_NAME): cv.string,
52 vol.Required(ATTR_LAST_NAME): cv.string,
53 vol.Required(ATTR_EMAIL): cv.string,
54 vol.Required(ATTR_PHONE): cv.string,
55 vol.Required(ATTR_ADDRESS): cv.string,
56 vol.Optional(ATTR_SHOW_MENU): cv.boolean,
57 vol.Optional(ATTR_ORDERS, default=[]): vol.All(
58 cv.ensure_list, [_ORDERS_SCHEMA]
63 extra=vol.ALLOW_EXTRA,
67 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
68 """Set up is called when Home Assistant is loading our component."""
71 component = EntityComponent[DominosOrder](_LOGGER, DOMAIN, hass)
72 hass.data[DOMAIN] = {}
73 entities: list[DominosOrder] = []
76 hass.services.register(
82 vol.Required(ATTR_ORDER_ENTITY): cv.entity_ids,
87 if conf.get(ATTR_SHOW_MENU):
90 for order_info
in conf.get(ATTR_ORDERS):
92 entities.append(order)
94 component.add_entities(entities)
101 """Main Dominos service."""
104 """Set up main service."""
105 conf = config[DOMAIN]
109 conf.get(ATTR_FIRST_NAME),
110 conf.get(ATTR_LAST_NAME),
111 conf.get(ATTR_EMAIL),
112 conf.get(ATTR_PHONE),
113 conf.get(ATTR_ADDRESS),
116 *self.
customercustomer.address.split(
","), country=conf.get(ATTR_COUNTRY)
125 """Handle ordering pizza."""
126 entity_ids = call.data[ATTR_ORDER_ENTITY]
130 for order
in self.
hasshass.data[DOMAIN][
"entities"]
131 if order.entity_id
in entity_ids
134 for order
in target_orders:
137 @Throttle(MIN_TIME_BETWEEN_STORE_UPDATES)
139 """Update the shared closest store (if open)."""
148 """Return the products from the closest stores menu."""
151 _LOGGER.warning(
"Cannot get menu. Store may be closed")
156 for product
in menu.products:
158 if isinstance(product.menu_data[
"Variants"], list):
159 variants =
", ".join(product.menu_data[
"Variants"])
161 variants = product.menu_data[
"Variants"]
162 item[
"name"] = product.name
163 item[
"variants"] = variants
164 product_entries.append(item)
166 return product_entries
170 """View to retrieve product list content."""
176 """Initialize suite view."""
181 """Retrieve if API is running."""
182 return self.json(self.
dominosdominos.get_menu())
186 """Represents a Dominos order entity."""
189 """Set up the entity."""
190 self.
_name_name = order_info[
"name"]
197 """Return the orders name."""
198 return self.
_name_name
202 """Return the orders product codes."""
207 """Return the true if orderable."""
212 """Return the state either closed, orderable or unorderable."""
213 if self.
dominosdominos.closest_store
is None:
215 return "orderable" if self.
_orderable_orderable
else "unorderable"
217 @Throttle(MIN_TIME_BETWEEN_UPDATES)
219 """Update the order state and refreshes the store."""
221 self.
dominosdominos.update_closest_store()
227 order = self.
orderorder()
234 """Create the order object."""
235 if self.
dominosdominos.closest_store
is None:
239 self.
dominosdominos.closest_store,
251 """Place the order."""
253 order = self.
orderorder()
258 "Attempted to order Dominos - Order invalid or store closed"
def __init__(self, order_info, dominos)
def __init__(self, dominos)
def __init__(self, hass, config)
None handle_order(self, ServiceCall call)
def update_closest_store(self)
bool setup(HomeAssistant hass, ConfigType config)